Hi All
I want to recreate a data file from matrix of two variables that only provides frequencies. The first variable is census tract and the second variable is housing type. I want to do this with syntax, because manually creating this will take too long and I'm always trying to improve my syntax writing skills. Here is an example of what I have. CensusTract HousingType1 HousingType2 HousingType3 145702 11 15 0 145601 8 50 3 145504 23 17 10 But I want to create a file that has them listed individually. Thus I would have 11 CensusTract 145702 with a housing type 1; 15 censustract 145702 with a housing type of 2 and so on. CensusTract HousingType 145702 1 145702 1 + 9 more 1 145702 2 + 14 more 2 I would really appreciate the help. Thanks Zana ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Tested.
data list list / CensusTract HousingType1 HousingType2 HousingType3. begin data 145702 11 15 0 145601 8 50 3 145504 23 17 10 end data. execute. varstocases make housecount from housingtype1 to housingtype3/index=housetype. loop #i=1 to housecount. xsave outfile='u:\housetest.sav' / keep=censustract housetype. end loop. execute. get file='u:\housetest.sav'. Gene Maguin -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Zana Dael Sent: Tuesday, May 06, 2014 9:33 AM To: [hidden email] Subject: Syntax to Create Multiples of Raw Data Hi All I want to recreate a data file from matrix of two variables that only provides frequencies. The first variable is census tract and the second variable is housing type. I want to do this with syntax, because manually creating this will take too long and I'm always trying to improve my syntax writing skills. Here is an example of what I have. CensusTract HousingType1 HousingType2 HousingType3 145702 11 15 0 145601 8 50 3 145504 23 17 10 But I want to create a file that has them listed individually. Thus I would have 11 CensusTract 145702 with a housing type 1; 15 censustract 145702 with a housing type of 2 and so on. CensusTract HousingType 145702 1 145702 1 + 9 more 1 145702 2 + 14 more 2 I would really appreciate the help. Thanks Zana ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
In reply to this post by Zana Dael
Thanks Eugene. That is so slick. Works beautifully, I have many more of
these census tracts, housing types to go. You saved me so much time and irritation. Thanks again. Zana On Tue, 6 May 2014 13:58:01 +0000, Maguin, Eugene <[hidden email]> wrote: >Tested. > >data list list / CensusTract HousingType1 HousingType2 HousingType3. >begin data >145702 11 15 0 >145601 8 50 3 >145504 23 17 10 >end data. >execute. >varstocases make housecount from housingtype1 to > >loop #i=1 to housecount. >xsave outfile='u:\housetest.sav' / keep=censustract housetype. >end loop. >execute. > >get file='u:\housetest.sav'. > > >Gene Maguin > >-----Original Message----- >From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of >Sent: Tuesday, May 06, 2014 9:33 AM >To: [hidden email] >Subject: Syntax to Create Multiples of Raw Data > >Hi All > >I want to recreate a data file from matrix of two variables that only provides frequencies. The first variable is census tract and the second variable is housing type. I want to do this with syntax, because manually creating this will take too long and I'm always trying to improve my syntax writing skills. > >Here is an example of what I have. >CensusTract HousingType1 HousingType2 HousingType3 >145702 11 15 0 >145601 8 50 3 >145504 23 17 10 > >But I want to create a file that has them listed individually. Thus I would have 11 CensusTract 145702 with a housing type 1; 15 censustract 145702 with a housing type of 2 and so on. >CensusTract HousingType >145702 1 >145702 1 >+ 9 more 1 >145702 2 >+ 14 more 2 > >I would really appreciate the help. > >Thanks > >Zana > >===================== >To manage your subscription to SPSSX-L, send a message to command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD > >===================== >To manage your subscription to SPSSX-L, send a message to >[hidden email] (not to SPSSX-L), with no body text except the >command. To leave the list, send the command >SIGNOFF SPSSX-L >For a list of commands to manage subscriptions, send the command >INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Administrator
|
In reply to this post by Zana Dael
see VECTOR, LOOP and XSAVE commands.
------------------------------------------------
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Administrator
|
In reply to this post by Maguin, Eugene
See 3 solutions below, the 2nd two avoid writing any user specified external file.
-- DATA LIST LIST/CensusTract HousingType1 HousingType2 HousingType3 . BEGIN DATA 145702 11 15 0 145601 8 50 3 145504 23 17 10 END DATA. VECTOR HT=HousingType1 TO HousingType3 . LOOP HousingType=1 TO 3. LOOP #=1 TO HT(HousingType). XSAVE OUTFILE 'C:\TEMP\Exploded.sav' / KEEP CensusTract HousingType. END LOOP. END LOOP. EXECUTE. GET FILE 'C:\TEMP\Exploded.sav' . DATA LIST LIST/CensusTract HousingType1 HousingType2 HousingType3 . BEGIN DATA 145702 11 15 0 145601 8 50 3 145504 23 17 10 END DATA. MATRIX. GET data / FILE *. LOOP #=1 TO NROW(data). LOOP ##=1 TO 3. DO IF data(#,##+1) GT 0. SAVE {MAKE(data(#,##+1),1,data(#,1)),MAKE(data(#,##+1),1,##)} /OUTFILE * /VARIABLES CensusTract HousingType. END IF. END LOOP. END LOOP. END MATRIX. DATA LIST LIST/CensusTract HousingType1 HousingType2 HousingType3 . BEGIN DATA 145702 11 15 0 145601 8 50 3 145504 23 17 10 END DATA. RECODE HousingType1 TO HousingType3 (0=SYSMIS). VARSTOCASES /MAKE HT FROM HousingType1 TO HousingType3/NULL=DROP/INDEX=index(3). MATRIX. GET data / FILE *. LOOP #=1 TO NROW(data). SAVE {MAKE(data(#,3),1,data(#,1)),MAKE(data(#,3),1,data(#,2))} /OUTFILE * /VARIABLES CensusTract HousingType. END LOOP. END MATRIX.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by Zana Dael
David,
I tried the 2nd solution and couldn't get it to work for the longest time. Then I realized I was making a big, dumb mistake. The syntax works great and really fast. Really cool. Thanks Zana On Tue, 6 May 2014 07:50:57 -0700, David Marso <[hidden email]> wrote: >See 3 solutions below, the 2nd two avoid writing any user specified external >file. >-- >DATA LIST LIST/CensusTract HousingType1 HousingType2 >HousingType3 . >BEGIN DATA >145702 11 15 0 >145601 8 50 3 >145504 23 17 10 >END DATA. >VECTOR HT=HousingType1 TO HousingType3 . >LOOP HousingType=1 TO 3. >LOOP #=1 TO HT(HousingType). >XSAVE OUTFILE 'C:\TEMP\Exploded.sav' / KEEP CensusTract HousingType. >END LOOP. >END LOOP. >EXECUTE. >GET FILE 'C:\TEMP\Exploded.sav' . > >DATA LIST LIST/CensusTract HousingType1 HousingType2 >HousingType3 . >BEGIN DATA >145702 11 15 0 >145601 8 50 3 >145504 23 17 10 >END DATA. > >MATRIX. >GET data / FILE *. >LOOP #=1 TO NROW(data). >LOOP ##=1 TO 3. >DO IF data(#,##+1) GT 0. >SAVE {MAKE(data(#,##+1),1,data(#,1)),MAKE(data(#,##+1),1,##)} > /OUTFILE * /VARIABLES CensusTract HousingType. >END IF. >END LOOP. >END LOOP. >END MATRIX. > >DATA LIST LIST/CensusTract HousingType1 HousingType2 >HousingType3 . >BEGIN DATA >145702 11 15 0 >145601 8 50 3 >145504 23 17 10 >END DATA. >RECODE HousingType1 TO HousingType3 (0=SYSMIS). >VARSTOCASES /MAKE HT FROM HousingType1 TO >HousingType3/NULL=DROP/INDEX=index(3). >MATRIX. >GET data / FILE *. >LOOP #=1 TO NROW(data). >SAVE {MAKE(data(#,3),1,data(#,1)),MAKE(data(#,3),1,data(#,2))} > /OUTFILE * /VARIABLES CensusTract HousingType. >END LOOP. >END MATRIX. > > > > > > >----- >Please reply to the list and not to my personal email. >Those desiring my consulting or training services please feel free to email >--- >"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." >Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" >-- >View this message in context: http://spssx- discussion.1045642.n5.nabble.com/Syntax-to-Create-Multiples-of-Raw-Data- tp5725812p5725822.html >Sent from the SPSSX Discussion mailing list archive at Nabble.com. > >===================== >To manage your subscription to SPSSX-L, send a message to >[hidden email] (not to SPSSX-L), with no body text except the >command. To leave the list, send the command >SIGNOFF SPSSX-L >For a list of commands to manage subscriptions, send the command >INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Administrator
|
I would probably use solution 3.
It is simpler and more efficient. VARSTOCASES is really quite speedy. Losing the inner loop and the DO IF will yield a gain in speed (not sure how much, don't have any benchmarks for this).
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Free forum by Nabble | Edit this page |