This post was updated on .
Hi:
I have a set of series of variables i.e. V1 to V6 (which are not constant - varies from time to time). Now I am checking these variables with a condition and if that is not satisfied I need to print the data by concatenating all the mentioned 6 variables data to a variable called 'err20'. Below is my SPSS code: DO REPEAT Var=V1 TO V6. IF (X ne 1 and NOT(SYSMIS(Var))) err20=concat(string(SERIAL,f10),",Var,",string(V1,f3) ,string(V2,f3),string(V3,f3),string(V4,f3),string(V5,f3),string(V6,f3),",Filter not satisfied but data appears"). END REPEAT. The Question is: As I stated above that the variables V1 to V6 are not constant i.e changes every time. lets say if I get another 4 variables added i.e. V1 to V10 Then i have to add these additional variables in the error statement manually i.e. I have to alter the code every time. Now I would like to know is their a way where I can put this above error statement in the loop where it should get incremented automatically when I change the variables at DO REPEAT statement. |
Administrator
|
I think it would help a lot if you provided a small example showing before and after views of the data set.
p.s. - I don't see the point of your DO-REPEAT below. It looks like the only place Var appears in the IF line is inside quotes, so you don't actually get substitution of V1 to V6 for Var, as far as I can tell. Does that syntax actually do what you want it to?
--
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 jagadishpchary
I'd like to add to what Bruce already said and ask you to state in words how this little piece of code is supposed to work.
Gene Maguin -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of jagadishpchary Sent: Tuesday, January 12, 2016 6:08 AM To: [hidden email] Subject: Incrementing automatically in a loop Hi: I have a set of series of variables i.e. V1 to V6 (which are not constant - varies from time to time). Now I am checking these variables with a condition and if that is not satisfied I need to print the data by concatenating all the mentioned 6 variables data to a variable called 'err20'. Below is my SPSS code: DO REPEAT Var=V1 TO V6. IF (X ne 1 and NOT(SYSMIS(Var))) err20=concat(string(SERIAL,f10),",Var,",string(V1,f3) ,string(V2,f3),string(V3,f3),string(V4,f3),string(V5,f3),string(V6,f3),",Filter not satisfied but data appears"). END REPEAT. The Question is: As I stated above that the variables V1 to V6 are not constant i.e changes every time. lets say if I get another 4 variables added i.e. V1 to V10 Then i have to add these additional variables in the error statement manually i.e. I have to alter the code every time. Now I would like to know is their a way where I can put this above error statement in the loop where it should get incremented automatically when I change the variables at DO REPEAT statement. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Incrementing-automatically-in-a-loop-tp5731246.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
Hi:
I have just given an example stating that the IF condition should be in a loop. However, I have the below syntax which concatenates the variables V1 to V6. IF (X ne 1 and NOT(SYSMIS(Var))) err20=concat(string(SERIAL,f10),string(V1,f3) ,string(V2,f3),string(V3,f3),string(V4,f3),string(V5,f3),string(V6,f3),",Filter not satisfied but data appears"). Now, if more variables are added - Let say (V6 to V10) then i need to add that variables in the above IF condition...then my syntax would be.. IF (X ne 1 and NOT(SYSMIS(Var))) err20=concat(string(SERIAL,f10),",Var,",string(V1,f3) ,string(V2,f3),string(V3,f3),string(V4,f3),string(V5,f3),string(V6,f3),string(V7,f3),string(V8,f3),string(V9,f3),string(V10,f3),",Filter not satisfied but data appears"). Hence i want to know is there any way where i can put the above condition in a loop. so that when another set of variables are added next time it should be easy for me to concatenate all the variables data. |
Administrator
|
In reply to this post by jagadishpchary
Hint:
STRING Newvar(A100). COMPUTE Newvar=string(SERIAL,f10). DO REPEAT var=blah blah blah. COMPUTE NewVar=CONCAT(RTRIM(NewVar)," ",STRING(var,F3) ). END REPEAT. If this doesn't do what you want then you will need to do what Gene and Bruce said. ---
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 jagadishpchary
To your specific question.
You do two things: a) test whether each variable meets the condition. And, b) if any variable passes the test, you construct the string. Now, as I read the code the same string is constructed repeatedly for every variable that passes the test. The string contains the values of every variable irrespective of whether it passed the test. So a simpler version would be to determine if any variable passes the test and if it does, then construct the string. So. String err20(aXXX). Count vmiss=v1 to v34(sysmis). Do if (x1 ne 1 and vmiss ne 34). Compute err20=string(SERIAL,f10),",Var,"). Do repeat x=v1 to v34. + compute err20=concat(rtrim(err20), string(x,f3)). End repeat. compute err20=concat(rtrim(err20), ",Filter not satisfied but data appears"). So this is easily expandable to any number of variables. The only thing you have to do is to make sure the variable count matches in the different places and adjust the string width. Gene Maguin -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of jagadishpchary Sent: Tuesday, January 12, 2016 11:10 AM To: [hidden email] Subject: Re: Concatenate automatically in a loop Hi: I have just given an example stating that the IF condition should be in a loop. However, I have the below syntax which concatenates the variables V1 to V6. IF (X ne 1 and NOT(SYSMIS(Var))) err20=concat(string(SERIAL,f10),string(V1,f3) ,string(V2,f3),string(V3,f3),string(V4,f3),string(V5,f3),string(V6,f3),",Filter not satisfied but data appears"). Now, if more variables are added - Let say (V6 to V10) then i need to add that variables in the above IF condition...then my syntax would be.. IF (X ne 1 and NOT(SYSMIS(Var))) err20=concat(string(SERIAL,f10),",Var,",string(V1,f3) ,string(V2,f3),string(V3,f3),string(V4,f3),string(V5,f3),string(V6,f3),string(V7,f3),string(V8,f3),string(V9,f3),string(V10,f3),",Filter not satisfied but data appears"). Hence i want to know is there any way where i can put the above condition in a loop. so that when another set of variables are added next time it should be easy for me to concatenate all the variables data. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Concatenate-automatically-in-a-loop-tp5731246p5731256.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 |
Thank you Gene Maguin:
I did few changes in the code and it worked well as per my requirement. Regards, Jagadish |
Free forum by Nabble | Edit this page |