Sorry. The format of the example wasn't correct. Here is the correct one.
Var_X Var_2 Var_5 Var_7 Var_9 2 2 2 2 5 5 5 5 7 7 7 7 9 9 9 9 Juergen |
Hi Juergen,
I am at a lost as to what you want to accomplish. Can you please elucidate further. Regards. Edward. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of Juergen Pueschel Sent: Thursday, November 02, 2006 12:03 PM To: [hidden email] Subject: Re: Defining variables depending on values - correction Sorry. The format of the example wasn't correct. Here is the correct one. Var_X Var_2 Var_5 Var_7 Var_9 2 2 2 2 5 5 5 5 7 7 7 7 9 9 9 9 Juergen |
In reply to this post by Juergen Pueschel
Hi Juergen,
I conjecture this is what you want . DO IF Var_X=2). COMPUTE Var_2 = 2. ELSE IF (Var_X=5). COMPUTE Var_5 = 5. ELSE IF (Var_X=7). COMPUTE Var_7 = 7. ELSE IF (Var_X=9). COMPUTE Var_7 = 9. END IF. EXECUTE. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of Juergen Pueschel Sent: Thursday, November 02, 2006 12:03 PM To: [hidden email] Subject: Re: Defining variables depending on values - correction Sorry. The format of the example wasn't correct. Here is the correct one. Var_X Var_2 Var_5 Var_7 Var_9 2 2 2 2 5 5 5 5 7 7 7 7 9 9 9 9 Juergen |
In reply to this post by Juergen Pueschel
Hi Edward,
yes, this is what I want. But my problem is: the variable VAR_X contains values with a range from 2 to 1000 (whereof only 120 values appear). And there are more data-files to come probably containing other values. What I need is a syntax/macro that automatically defines a set of variables depending on the values in VAR_X. I already tried the vector-function in combination with a loop ... / do if - structure, but the result is a variable set, that contains 999 variables, whereof only 120 variables contain values. What the syntax should do: Case 1: VAR_X = 2 -> compute Var_2 = 2 Case 2: VAR_X = 2 -> Var_2 = 2 Case 3: VAR_X = 5 -> compute Var_5 = 5 Case 4: VAR_X = 5 -> Var_5 = 5 Case 5: VAR_X = 7 -> compute Var_7 = 7 Case 6: VAR_X = 7 -> Var_7 = 7 .... Case 10000: VAR_X = 859 compute Var_859 = 859 Case 10001: VAR_X = 859 Var_859 = 1 What the syntax should not do: Var_X contains no 1, 3, 4 etc. -> do NOT compute VAR_1, VAR_3, VAR_4 etc. Best regards Juergen On Thu, 2 Nov 2006 12:42:51 -0500, Edward Boadi <[hidden email]> wrote: >Hi Juergen, > >I conjecture this is what you want . > >DO IF Var_X=2). > COMPUTE Var_2 = 2. >ELSE IF (Var_X=5). > COMPUTE Var_5 = 5. >ELSE IF (Var_X=7). > COMPUTE Var_7 = 7. >ELSE IF (Var_X=9). > COMPUTE Var_7 = 9. >END IF. >EXECUTE. > >-----Original Message----- >From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of >Juergen Pueschel >Sent: Thursday, November 02, 2006 12:03 PM >To: [hidden email] >Subject: Re: Defining variables depending on values - correction > > >Sorry. The format of the example wasn't correct. Here is the correct one. > >Var_X Var_2 Var_5 Var_7 Var_9 >2 2 >2 2 >5 5 >5 5 >7 7 >7 7 >9 9 >9 9 > >Juergen |
In reply to this post by Juergen Pueschel
Juergen:
Does this do what you want? ** sample data. SET SEED = 2006110310. INPUT PROGRAM. LOOP i =1 TO 50. COMPUTE var_x = TRUNC(UNIFORM(1)*100). END CASE. END LOOP. END FILE. END INPUT PROGRAM. FREQUENCIES var_x. ** the dataset should not have var_x = 2,4,5,6,7,9,10 (and other values). ** -- this is controlled by SET SEED above. ** create var_1 to var_100 and put the values of var_x into the matching value. VECTOR var_(100F8.0). LOOP #i = 1 TO 100. DO IF var_x = (#i). COMPUTE var_(#i) = var_x. END IF. END LOOP. EXECUTE. ** identify and delete variables with no values from var_x. FLIP. comp valid = sum(var001 to var050). SELECT IF VALID GE 0. FLIP VARIBLES = var001 TO var050. Notes 1) if you have string variables in your dataset, FLIP will obliterate them. You can get around this by creating a key, saving the strings out to a separate file, and matching after the unneeded var_1 TO var_n variables are removed. 2) This is a brute force method. If you have 10,000 cases, FLIP create 10,000 variables. This can take a long time to complete on larger datasets/ slower machines. I bet there is an elegant/ programmable way to do this. If not, kick it off Friday and check back on Monday to see how far along the job is :~) --jim -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Juergen Pueschel Sent: Friday, November 03, 2006 2:45 AM To: [hidden email] Subject: Re: Defining variables depending on values - correction Hi Edward, yes, this is what I want. But my problem is: the variable VAR_X contains values with a range from 2 to 1000 (whereof only 120 values appear). And there are more data-files to come probably containing other values. What I need is a syntax/macro that automatically defines a set of variables depending on the values in VAR_X. I already tried the vector-function in combination with a loop ... / do if - structure, but the result is a variable set, that contains 999 variables, whereof only 120 variables contain values. What the syntax should do: Case 1: VAR_X = 2 -> compute Var_2 = 2 Case 2: VAR_X = 2 -> Var_2 = 2 Case 3: VAR_X = 5 -> compute Var_5 = 5 Case 4: VAR_X = 5 -> Var_5 = 5 Case 5: VAR_X = 7 -> compute Var_7 = 7 Case 6: VAR_X = 7 -> Var_7 = 7 .... Case 10000: VAR_X = 859 compute Var_859 = 859 Case 10001: VAR_X = 859 Var_859 = 1 What the syntax should not do: Var_X contains no 1, 3, 4 etc. -> do NOT compute VAR_1, VAR_3, VAR_4 etc. Best regards Juergen On Thu, 2 Nov 2006 12:42:51 -0500, Edward Boadi <[hidden email]> wrote: >Hi Juergen, > >I conjecture this is what you want . > >DO IF Var_X=2). > COMPUTE Var_2 = 2. >ELSE IF (Var_X=5). > COMPUTE Var_5 = 5. >ELSE IF (Var_X=7). > COMPUTE Var_7 = 7. >ELSE IF (Var_X=9). > COMPUTE Var_7 = 9. >END IF. >EXECUTE. > >-----Original Message----- >From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of >Juergen Pueschel >Sent: Thursday, November 02, 2006 12:03 PM >To: [hidden email] >Subject: Re: Defining variables depending on values - correction > > >Sorry. The format of the example wasn't correct. Here is the correct one. > >Var_X Var_2 Var_5 Var_7 Var_9 >2 2 >2 2 >5 5 >5 5 >7 7 >7 7 >9 9 >9 9 > >Juergen |
In reply to this post by Juergen Pueschel
Hi Jim,
it works! Even with more than 40000 cases. Thank you very much! Juergen On Fri, 3 Nov 2006 11:14:47 -0600, Marks, Jim <[hidden email]> wrote: >Juergen: > >Does this do what you want? > >** sample data. >SET SEED = 2006110310. > >INPUT PROGRAM. >LOOP i =1 TO 50. >COMPUTE var_x = TRUNC(UNIFORM(1)*100). >END CASE. >END LOOP. >END FILE. >END INPUT PROGRAM. > >FREQUENCIES var_x. > >** the dataset should not have var_x = 2,4,5,6,7,9,10 (and other >values). >** -- this is controlled by SET SEED above. > >** create var_1 to var_100 and put the values of var_x into the matching >value. >VECTOR var_(100F8.0). >LOOP #i = 1 TO 100. >DO IF var_x = (#i). >COMPUTE var_(#i) = var_x. >END IF. >END LOOP. >EXECUTE. > >** identify and delete variables with no values from var_x. > >FLIP. >comp valid = sum(var001 to var050). >SELECT IF VALID GE 0. >FLIP VARIBLES = var001 TO var050. > > >Notes >1) if you have string variables in your dataset, FLIP will obliterate >them. You can get around this by creating a key, saving the strings out >to a separate file, and matching after the unneeded var_1 TO var_n >variables are removed. > >2) This is a brute force method. If you have 10,000 cases, FLIP create >10,000 variables. This can take a long time to complete on larger >datasets/ slower machines. > >I bet there is an elegant/ programmable way to do this. If not, kick it >off Friday and check back on Monday to see how far along the job is :~) > >--jim > > > >-----Original Message----- >From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of >Juergen Pueschel >Sent: Friday, November 03, 2006 2:45 AM >To: [hidden email] >Subject: Re: Defining variables depending on values - correction > >Hi Edward, > >yes, this is what I want. But my problem is: the variable VAR_X contains >values with a range from 2 to 1000 (whereof only 120 values appear). And >there are more data-files to come probably containing other values. > >What I need is a syntax/macro that automatically defines a set of >variables depending on the values in VAR_X. > >I already tried the vector-function in combination with a loop ... / do >if - structure, but the result is a variable set, that contains 999 >variables, whereof only 120 variables contain values. > >What the syntax should do: >Case 1: VAR_X = 2 -> compute Var_2 = 2 >Case 2: VAR_X = 2 -> Var_2 = 2 >Case 3: VAR_X = 5 -> compute Var_5 = 5 >Case 4: VAR_X = 5 -> Var_5 = 5 >Case 5: VAR_X = 7 -> compute Var_7 = 7 >Case 6: VAR_X = 7 -> Var_7 = 7 >.... >Case 10000: VAR_X = 859 compute Var_859 = 859 Case 10001: VAR_X = 859 >Var_859 = 1 > >What the syntax should not do: >Var_X contains no 1, 3, 4 etc. -> do NOT compute VAR_1, VAR_3, VAR_4 >etc. > >Best regards > >Juergen > > > >On Thu, 2 Nov 2006 12:42:51 -0500, Edward Boadi <[hidden email]> >wrote: > >>Hi Juergen, >> >>I conjecture this is what you want . >> >>DO IF Var_X=2). >> COMPUTE Var_2 = 2. >>ELSE IF (Var_X=5). >> COMPUTE Var_5 = 5. >>ELSE IF (Var_X=7). >> COMPUTE Var_7 = 7. >>ELSE IF (Var_X=9). >> COMPUTE Var_7 = 9. >>END IF. >>EXECUTE. >> >>-----Original Message----- >>From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of > >>Juergen Pueschel >>Sent: Thursday, November 02, 2006 12:03 PM >>To: [hidden email] >>Subject: Re: Defining variables depending on values - correction >> >> >>Sorry. The format of the example wasn't correct. Here is the correct >one. >> >>Var_X Var_2 Var_5 Var_7 Var_9 >>2 2 >>2 2 >>5 5 >>5 5 >>7 7 >>7 7 >>9 9 >>9 9 >> >>Juergen |
Free forum by Nabble | Edit this page |