Hi Everyone, Okay – I have looked everywhere I can think of and tried really hard not to come to you with this question but, here goes (incidentally, I have always wondered about this issue anyway): I have a Master Syntax Program that will be run on a series of different data files. 1) Each file will have a different number of variables that capture “like” which come as tlike, tlik0001, tlik0002 etc. 2) The list always begins with tlike, the second variable is always tlik0001, and the last variable can be anything out to tlik0050. 3) Due to the differing number of variables, I have this set up as a manual process (below) where you paste the tlike variables into the first do repeat statement where the data is put into empty variables that I have already created to hold the data. The data can then be used in a loop with vectors and at least a manual adjustment doesn’t have to take place there. Question: Is there a way you can set a loop or a do repeat statement to exit if a variable isn’t present? Or, can you somehow move data into a pre-existing vector to the extent that the data is present to go into the vector? Any ideas will be much appreciated. DO REPEAT A= tlike tlik0001 tlik0002 tlik0003 tlik0004 tlik0005 tlik0006 tlik0007 tlik0008 tlik0009 tlik0010 tlik0011 /B=TLIKE1 TO TLIKE12 IF (A GE 1) B=A. END REPEAT PRINT. execute. vector tlikex=tlike1 to tlike50. LOOP time_x = 1 to 50. COMPUTE like_product=tlikex(time_x). XSAVE OUTFILE 'c:\datafiles\test.sav' /keep = like_product. END LOOP. execute. Sincerely, Jeanne Eidex |
This is a good example of needing to raise
the level of abstraction in a job so that it is not tied to an exact list
of variables.
That is the purpose of the SPSSINC SELECT VARIABLES extension command (from the SPSS Community at www.ibm.com/developerworks/spssdevcentral) This syntax will select all variables with names that look like "tlik" followed by at least one digit. It defines a macro named !like which can then be used in other syntax expressions. This command has a variety of other options such as controlling the variable order and using other variable properties in the selection. Note that both the macro name and the pattern parameters need to be quoted. SPSSINC SELECT VARIABLES MACRONAME="!like" /PROPERTIES PATTERN = "tlik\d+". It appears as the Utilities>Define Variable Macro dialog box after installation. HTH, Jon Peck Senior Software Engineer, IBM [hidden email] 312-651-3435 From: Jeanne Eidex <[hidden email]> To: [hidden email] Date: 02/21/2011 12:59 PM Subject: [SPSSX-L] Sent by: "SPSSX(r) Discussion" <[hidden email]> Hi Everyone, Okay – I have looked everywhere I can think of and tried really hard not to come to you with this question but, here goes (incidentally, I have always wondered about this issue anyway): I have a Master Syntax Program that will be run on a series of different data files. 1) Each file will have a different number of variables that capture “like” which come as tlike, tlik0001, tlik0002 etc. 2) The list always begins with tlike, the second variable is always tlik0001, and the last variable can be anything out to tlik0050. 3) Due to the differing number of variables, I have this set up as a manual process (below) where you paste the tlike variables into the first do repeat statement where the data is put into empty variables that I have already created to hold the data. The data can then be used in a loop with vectors and at least a manual adjustment doesn’t have to take place there. Question: Is there a way you can set a loop or a do repeat statement to exit if a variable isn’t present? Or, can you somehow move data into a pre-existing vector to the extent that the data is present to go into the vector? Any ideas will be much appreciated. DO REPEAT A= tlike tlik0001 tlik0002 tlik0003 tlik0004 tlik0005 tlik0006 tlik0007 tlik0008 tlik0009 tlik0010 tlik0011 /B=TLIKE1 TO TLIKE12 IF (A GE 1) B=A. END REPEAT PRINT. execute. vector tlikex=tlike1 to tlike50. LOOP time_x = 1 to 50. COMPUTE like_product=tlikex(time_x). XSAVE OUTFILE 'c:\datafiles\test.sav' /keep = like_product. END LOOP. execute. Sincerely, Jeanne Eidex |
That's handy. But, since the OP wanted to include vars of the form tlike, tlik1, tlik2, ..., shouldn't the pattern in this example be "tlike?\d+"? Cheers!!Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From: Jon K Peck <[hidden email]> To: [hidden email] Sent: Mon, February 21, 2011 9:28:08 PM Subject: Re: [SPSSX-L] This is a good example of needing to raise the level of abstraction in a job so that it is not tied to an exact list of variables. That is the purpose of the SPSSINC SELECT VARIABLES extension command (from the SPSS Community at www.ibm.com/developerworks/spssdevcentral) This syntax will select all variables with names that look like "tlik" followed by at least one digit. It defines a macro named !like which can then be used in other syntax expressions. This command has a variety of other options such as controlling the variable order and using other variable properties in the selection. Note that both the macro name and the pattern parameters need to be quoted. SPSSINC SELECT VARIABLES MACRONAME="!like" /PROPERTIES PATTERN = "tlik\d+". It appears as the Utilities>Define Variable Macro dialog box after installation. HTH, Jon Peck Senior Software Engineer, IBM [hidden email] 312-651-3435 From: Jeanne Eidex <[hidden email]> To: [hidden email] Date: 02/21/2011 12:59 PM Subject: [SPSSX-L] Sent by: "SPSSX(r) Discussion" <[hidden email]> Hi Everyone, Okay – I have looked everywhere I can think of and tried really hard not to come to you with this question but, here goes (incidentally, I have always wondered about this issue anyway): I have a Master Syntax Program that will be run on a series of different data files. 1) Each file will have a different number of variables that capture “like” which come as tlike, tlik0001, tlik0002 etc. 2) The list always begins with tlike, the second variable is always tlik0001, and the last variable can be anything out to tlik0050. 3) Due to the differing number of variables, I have this set up as a manual process (below) where you paste the tlike variables into the first do repeat statement where the data is put into empty variables that I have already created to hold the data. The data can then be used in a loop with vectors and at least a manual adjustment doesn’t have to take place there. Question: Is there a way you can set a loop or a do repeat statement to exit if a variable isn’t present? Or, can you somehow move data into a pre-existing vector to the extent that the data is present to go into the vector? Any ideas will be much appreciated. DO REPEAT A= tlike tlik0001 tlik0002 tlik0003 tlik0004 tlik0005 tlik0006 tlik0007 tlik0008 tlik0009 tlik0010 tlik0011 /B=TLIKE1 TO TLIKE12 IF (A GE 1) B=A. END REPEAT PRINT. execute. vector tlikex=tlike1 to tlike50. LOOP time_x = 1 to 50. COMPUTE like_product=tlikex(time_x). XSAVE OUTFILE 'c:\datafiles\test.sav' /keep = like_product. END LOOP. execute. Sincerely, Jeanne Eidex |
No. I left tlike out of the list
since it is being compared with the tlikn variables.
Jon Peck Senior Software Engineer, IBM [hidden email] 312-651-3435 From: Albert-Jan Roskam <[hidden email]> To: [hidden email] Date: 02/22/2011 12:44 AM Subject: Re: [SPSSX-L] Sent by: "SPSSX(r) Discussion" <[hidden email]> That's handy. But, since the OP wanted to include vars of the form tlike, tlik1, tlik2, ..., shouldn't the pattern in this example be "tlike?\d+"? Cheers!! Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From: Jon K Peck <[hidden email]> To: [hidden email] Sent: Mon, February 21, 2011 9:28:08 PM Subject: Re: [SPSSX-L] This is a good example of needing to raise the level of abstraction in a job so that it is not tied to an exact list of variables. That is the purpose of the SPSSINC SELECT VARIABLES extension command (from the SPSS Community at www.ibm.com/developerworks/spssdevcentral) This syntax will select all variables with names that look like "tlik" followed by at least one digit. It defines a macro named !like which can then be used in other syntax expressions. This command has a variety of other options such as controlling the variable order and using other variable properties in the selection. Note that both the macro name and the pattern parameters need to be quoted. SPSSINC SELECT VARIABLES MACRONAME="!like" /PROPERTIES PATTERN = "tlik\d+". It appears as the Utilities>Define Variable Macro dialog box after installation. HTH, Jon Peck Senior Software Engineer, IBM [hidden email] 312-651-3435 From: Jeanne Eidex <[hidden email]> To: [hidden email] Date: 02/21/2011 12:59 PM Subject: [SPSSX-L] Sent by: "SPSSX(r) Discussion" <[hidden email]> Hi Everyone, Okay – I have looked everywhere I can think of and tried really hard not to come to you with this question but, here goes (incidentally, I have always wondered about this issue anyway): I have a Master Syntax Program that will be run on a series of different data files. 1) Each file will have a different number of variables that capture “like” which come as tlike, tlik0001, tlik0002 etc. 2) The list always begins with tlike, the second variable is always tlik0001, and the last variable can be anything out to tlik0050. 3) Due to the differing number of variables, I have this set up as a manual process (below) where you paste the tlike variables into the first do repeat statement where the data is put into empty variables that I have already created to hold the data. The data can then be used in a loop with vectors and at least a manual adjustment doesn’t have to take place there. Question: Is there a way you can set a loop or a do repeat statement to exit if a variable isn’t present? Or, can you somehow move data into a pre-existing vector to the extent that the data is present to go into the vector? Any ideas will be much appreciated. DO REPEAT A= tlike tlik0001 tlik0002 tlik0003 tlik0004 tlik0005 tlik0006 tlik0007 tlik0008 tlik0009 tlik0010 tlik0011 /B=TLIKE1 TO TLIKE12 IF (A GE 1) B=A. END REPEAT PRINT. execute. vector tlikex=tlike1 to tlike50. LOOP time_x = 1 to 50. COMPUTE like_product=tlikex(time_x). XSAVE OUTFILE 'c:\datafiles\test.sav' /keep = like_product. END LOOP. execute. Sincerely, Jeanne Eidex |
Free forum by Nabble | Edit this page |