I would like to add the following structure to an existing file with cases. Unfortunately I don't find an elegant and short solution. Thanks for a little help.
INPUT PROGRAM. LOOP k = 40 to 69 by 1. loop p =0.01 to 0.99 by 0.01. end case. end loop. END LOOP. end file. END INPUT PROGRAM. EXECUTE. RECODE k (MISSING=0). EXECUTE. DO IF k = 0. COMPUTE k=LAG(k). END IF. EXECUTE.
Dr. Frank Gaeth
|
Administrator
|
Frank, adding one line to your INPUT PROGRAM takes care of the cases where k is missing.
INPUT PROGRAM. LOOP k = 40 to 69 by 1. loop p =0.01 to 0.99 by 0.01. if missing(k) k = lag(k). /* Deal with missing k. end case. end loop. END LOOP. end file. END INPUT PROGRAM. EXECUTE. I'm not sure what you mean when you say you want to add this structure to an existing file. It *sounds* like you want to merge files via MATCH FILES. Are there key variables to match on? HTH.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
In reply to this post by drfg2008
Are you trying to add cases to an existing file?
-----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of drfg2008 Sent: Wednesday, September 26, 2012 7:23 AM To: [hidden email] Subject: loop I would like to add the following structure to an existing file with cases. Unfortunately I don't find an elegant and short solution. Thanks for a little help. INPUT PROGRAM. LOOP k = 40 to 69 by 1. loop p =0.01 to 0.99 by 0.01. end case. end loop. END LOOP. end file. END INPUT PROGRAM. EXECUTE. RECODE k (MISSING=0). EXECUTE. DO IF k = 0. COMPUTE k=LAG(k). END IF. EXECUTE. ----- Dr. Frank Gaeth FU-Berlin -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/loop-tp5715276.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 |
In reply to this post by Bruce Weaver
Thank you. Yes, the existing file has the two variables:
k , p and I would like to add all combinations of k = 40 to 69 with 0.001 to 0.99 to that existing file. When I use input file, SPSS creates a new file instead of adding these combination to the existing file. (Thank you for the line if missing(k) k = lag(k). /* Deal with missing k. - That's already one step further.)
Dr. Frank Gaeth
|
In reply to this post by drfg2008
A general question: does an input program-end input program section work with an existing file? That seems to be implied here but I assumed that was never possible.
In terms of this code, k is never missing and k is never 0, so what is the point of the six lines beginning with 'recode'? Gene Maguin -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of drfg2008 Sent: Wednesday, September 26, 2012 9:23 AM To: [hidden email] Subject: loop I would like to add the following structure to an existing file with cases. Unfortunately I don't find an elegant and short solution. Thanks for a little help. INPUT PROGRAM. LOOP k = 40 to 69 by 1. loop p =0.01 to 0.99 by 0.01. end case. end loop. END LOOP. end file. END INPUT PROGRAM. EXECUTE. RECODE k (MISSING=0). EXECUTE. DO IF k = 0. COMPUTE k=LAG(k). END IF. EXECUTE. ----- Dr. Frank Gaeth FU-Berlin -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/loop-tp5715276.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 |
In reply to this post by drfg2008
Is this what you are looking for?
Are you trying to create something like a "backbone" to hand data on? INPUT PROGRAM. LOOP k = 40 to 69 by 1. leave k. loop p =0.01 to 0.99 by 0.01. end case. end loop. END LOOP. end file. END INPUT PROGRAM. formats k (f2) p(f4.2). EXECUTE. Art Kendall Social Research Consultants On 9/26/2012 9:23 AM, drfg2008 wrote: > I would like to add the following structure to an existing file with cases. > Unfortunately I don't find an elegant and short solution. Thanks for a > little help. > > > INPUT PROGRAM. > LOOP k = 40 to 69 by 1. > loop p =0.01 to 0.99 by 0.01. > end case. > end loop. > END LOOP. > end file. > END INPUT PROGRAM. > EXECUTE. > > RECODE k (MISSING=0). > EXECUTE. > DO IF k = 0. > COMPUTE k=LAG(k). > END IF. > EXECUTE. > > > > > ----- > Dr. Frank Gaeth > FU-Berlin > > -- > View this message in context: http://spssx-discussion.1045642.n5.nabble.com/loop-tp5715276.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
Art Kendall
Social Research Consultants |
That should be to "hang" data on.
Art Kendall Social Research Consultants On 9/26/2012 10:29 AM, Art Kendall wrote: > Is this what you are looking for? > Are you trying to create something like a "backbone" to hand data on? > > INPUT PROGRAM. > LOOP k = 40 to 69 by 1. > leave k. > loop p =0.01 to 0.99 by 0.01. > end case. > end loop. > END LOOP. > end file. > END INPUT PROGRAM. > formats k (f2) p(f4.2). > EXECUTE. > > Art Kendall > Social Research Consultants > > On 9/26/2012 9:23 AM, drfg2008 wrote: >> I would like to add the following structure to an existing file with >> cases. >> Unfortunately I don't find an elegant and short solution. Thanks for a >> little help. >> >> >> INPUT PROGRAM. >> LOOP k = 40 to 69 by 1. >> loop p =0.01 to 0.99 by 0.01. >> end case. >> end loop. >> END LOOP. >> end file. >> END INPUT PROGRAM. >> EXECUTE. >> >> RECODE k (MISSING=0). >> EXECUTE. >> DO IF k = 0. >> COMPUTE k=LAG(k). >> END IF. >> EXECUTE. >> >> >> >> >> ----- >> Dr. Frank Gaeth >> FU-Berlin >> >> -- >> View this message in context: >> http://spssx-discussion.1045642.n5.nabble.com/loop-tp5715276.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 > ===================== 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
Art Kendall
Social Research Consultants |
Administrator
|
In reply to this post by drfg2008
Ah hell Frank ;-)
You want short? You want elegant? Can't hardly get shorter or more elegant than this ;-)))))) DATA LIST FREE / k p. begin data 1 .1 2 .4 3 .3 4 .1 5 .5 6 .7 end data. DATASET NAME raw. MATRIX. SAVE ({KRONEKER(T({40:69}),MAKE(99,1,1)),KRONEKER(MAKE(30,1,1), T({1:99}/100))}) / OUTFILE * / VARIABLES k p. END MATRIX. ADD FILES / FILE raw /IN=OLD/ FILE * . EXE.
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 drfg2008
Can't really generate NEW cases into an existing data set using INPUT PROGRAM or **ANY** other sorcery.
Don't need LAG, just use LEAVE k. See my incredibly long winded solution below. ;-) --
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 David Marso
That's pretty slick, David. But as I understood it, Frank wants a MATCH FILES, not ADD FILES. I.e., I *think* he just wants to fill in the cases where the desired combinations of k and p are missing.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
Administrator
|
This post was updated on .
"I *think* he just wants to fill in the cases"
InterNeTelepathy? ;-) As usual, we'll probably eventually find out ;-) Maybe if original is SORTED on k p. DATA LIST FREE / k p. begin data 39 .12 40 .45 45 .32 46 .10 50 .50 70 .70 end data. SORT CASES BY k p. DATASET NAME raw. MATRIX. SAVE ({KRONEKER(T({40:69}),MAKE(99,1,1)),KRONEKER(MAKE(30,1,1),T({1:99}/100))}) / OUTFILE * / VARIABLES k p. END MATRIX. ADD FILES / FILE raw /IN=OLD/ FILE * /BY k p. EXECUTE.
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
|
Here is an '?alternative?' approach but note the requirement of an external file and all that 'extra' code (note the TEMPORARY DO IF blah blah blah...ADD FILES ...then who wants to do the ERASE FILE etc (usually the target seems to be in use etc...).
So, welcome to my world (MATRIX may look a bit terse and obscure but it certainly packs a punch and makes so much of my old school postings seem tired. Note in older versions MATRIX would need to write the external file but these days you can have multiple open files so there is no need to write to disk unlike the XSAVE. The other idea using INPUT PROGRAM will work too but it is a matter of dataset management and DON'T forget your LEAVE. DATA LIST FREE / k p. begin data 40 .15 42 .42 45 .35 47 .16 50 .57 60 .72 end data. DATASET NAME raw. TEMPORARY. DO IF $CASENUM EQ 1. LOOP K=40 TO 69. LOOP #P=1 TO 99. COMPUTE P=#P/100. XSAVE OUTFILE 'C:\TEMP.temp.sav' . END LOOP. END LOOP. END IF. EXECUTE. ADD FILES / FILE */IN=orig / FILE 'C:\TEMP.temp.sav' / IN=filled/ BY k p. CACHE. EXECUTE. ERASE FILE 'C:\TEMP.temp.sav' . *** NOTE THAT REMOVING EITHER the CACHE or the Final EXECUTE produces this error. >Error # 2307 in column 13. Text: C:\TEMP.temp.sav >The specified file exists but cannot be erased - possibly because it is a >read-only file or is already in use. >Execution of this command stops. DATA LIST FREE / k p. begin data 40 .155 42 .42 45 .35 47 .16 50 .57 60 .72 end data. DATASET NAME raw. DATASET DECLARE ip. INPUT PROGRAM. + LOOP K=40 TO 69. + LOOP #P=1 TO 99. + COMPUTE P=#P/100. + LEAVE K. + END CASE. + END LOOP. + END LOOP. + END FILE. END INPUT PROGRAM. ADD FILES / FILE * / FILE raw / BY k p. EXE.
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?" |
thanks everyone!
( The purpose is only to add it to an existing file. Somehow. )
Dr. Frank Gaeth
|
Administrator
|
See my 3 line solution!!! It does precisely that!
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
|
Assuming Frank means ADD FILES when he says "add to an existing file". We're still in the realm of interneTelepathy, if you ask me. ;-)
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
Administrator
|
I suspect my MATRIX solution might be on the border of grokability without massive infusions of caffeine.
MATRIX. SAVE ({KRONEKER(T({40:69}),MAKE(99,1,1)),KRONEKER(MAKE(30,1,1),T({1:99}/100))}) / OUTFILE * / VARIABLES k p. END MATRIX. Let's unpack that. {40,69} is shorthand for {40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60.......,69} T({40,69}) turns this row array into a column array. MAKE(99,1,1) creates a column array of length 99 consisting of 1's . KRONEKER(A,B) multiplies B into each element of A. So: KRONEKER(T({40:69}),MAKE(99,1,1)) constructs a 30*99 row , 1 column matrix of the sequence 40,41...69 and repeats each element 99 times. ie 40 99 times, 41 99 times etc. Similarly T({1:99}/100)) builds a column array of {.01,.02,.03 ...... .99} The KRONEKER(MAKE(30,1,1),T({1:99}/100)) simply makes each {.01...,.99} repeat 30 times. Finally {a,b} appends the columns of a and b so we get 40, .01 40, .02 ...... 40, .99 41, .01 ... 41, .99 ... 69, .99 SAVE using OUTFILE * pops the beast into a new data set and makes it the active file. Note that surrounding a complex expression on SAVE with () allows one to get away with this one liner. -- If you have followed this discussion and truly GROKed it you might be on the way to becoming a "MATRIX-MASTER".
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
|
Another though comes to mind re what Frank means by adding cases to an existing file.
It exists on disk but is not open in SPSS? In that case you will want to look into the SPSSIO.DLL documentation and look at the spssOpenAppend method. I don't write code to the IODLL for free. Sorry!
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 |