Hi All,
I have syntax that count the responses for each questions (total 137 questions) and if the responses' count is less than 5 it makes the variable symis /blank. The problem with the existing syntax is that it is very lengthy . I want to run the syntax in loop . I write the looping code but it is not working ..No error coming but transformation pending. LOOPING SYNTAX : VECTOR Count_Q=Count_Q1 TO Count_Q137. FOR #I= 1 TO 137. DO IF (Count_Q(#I) < 5). comp P6_0001 = $sysmis. comp P5_0001 = $sysmis. comp P4_0001 = $sysmis. comp P3_0001 = $sysmis. comp P2_0001 = $sysmis. comp P1_0001 = $sysmis. comp Mean_0001 = $sysmis. END IF. END LOOP. EXISTING SYNTAX (WITHOUT LOOPING). **FOR Q1. DO IF (Count_Q1 < 5). comp P6_0001 = $sysmis. comp P5_0001 = $sysmis. comp P4_0001 = $sysmis. comp P3_0001 = $sysmis. comp P2_0001 = $sysmis. comp P1_0001 = $sysmis. comp Mean_0001 = $sysmis. END IF. **FOR Q2. DO IF (Count_Q2 < 5). comp P6_0001 = $sysmis. comp P5_0001 = $sysmis. comp P4_0001 = $sysmis. comp P3_0001 = $sysmis. comp P2_0001 = $sysmis. comp P1_0001 = $sysmis. comp Mean_0001 = $sysmis. END IF. .. Same code till Q137. As i am new to looping and vector please review my created syntax and correct if if wrong or suggest better way to do the same . Thanks in advance ! |
Sandy,
I'm very confused by your non-looping syntax. It looks like that you have these 137 variables, count_q1 to count_q137, and then you have these other 7 variables, p1_0001 to p6_0001 and mean_0001, and if any of count_q1 to count_q137 are less than 5 you sysmis out p1_0001 to p6_0001, mean_0001. I just don't understand what you are doing. How does p1_0001 to p6_0001 and mean_0001 relate to count_q1 to count_q137 and why do you cycle through p1_0001 to p6_0001, mean_0001 137 times? I think we need to understand this part first. Gene Maguin -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Sandy Sent: Wednesday, March 21, 2012 1:59 PM To: [hidden email] Subject: looping Hi All, I have syntax that count the responses for each questions (total 137 questions) and if the responses' count is less than 5 it makes the variable symis /blank. The problem with the existing syntax is that it is very lengthy . I want to run the syntax in loop . I write the looping code but it is not working ..No error coming but transformation pending. LOOPING SYNTAX : VECTOR Count_Q=Count_Q1 TO Count_Q137. FOR #I= 1 TO 137. DO IF (Count_Q(#I) < 5). comp P6_0001 = $sysmis. comp P5_0001 = $sysmis. comp P4_0001 = $sysmis. comp P3_0001 = $sysmis. comp P2_0001 = $sysmis. comp P1_0001 = $sysmis. comp Mean_0001 = $sysmis. END IF. END LOOP. EXISTING SYNTAX (WITHOUT LOOPING). **FOR Q1. DO IF (Count_Q1 < 5). comp P6_0001 = $sysmis. comp P5_0001 = $sysmis. comp P4_0001 = $sysmis. comp P3_0001 = $sysmis. comp P2_0001 = $sysmis. comp P1_0001 = $sysmis. comp Mean_0001 = $sysmis. END IF. **FOR Q2. DO IF (Count_Q2 < 5). comp P6_0001 = $sysmis. comp P5_0001 = $sysmis. comp P4_0001 = $sysmis. comp P3_0001 = $sysmis. comp P2_0001 = $sysmis. comp P1_0001 = $sysmis. comp Mean_0001 = $sysmis. END IF. .. Same code till Q137. As i am new to looping and vector please review my created syntax and correct if if wrong or suggest better way to do the same . Thanks in advance ! -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/looping-tp5583668p5583668.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 |
count_q1 to count_q137 are variables wherein number of responses in each question for 50-60 organisation....
p1_0001 to p6_0001 are variables wherein % score of scale 1-6 (Strongly Disagree - Strongly Agree). If number of responses is less than 5 then we exclude that organisation / department from analysis.... so if number of responses is less than 5 we would sysmis out the %1-%6 score . |
In reply to this post by Sandy
Did you put "exe" at the end of the code?
Matthew J Poes Research Data Specialist Center for Prevention Research and Development University of Illinois 510 Devonshire Dr. Champaign, IL 61820 Phone: 217-265-4576 email: [hidden email] -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Sandy Sent: Wednesday, March 21, 2012 12:59 PM To: [hidden email] Subject: looping Hi All, I have syntax that count the responses for each questions (total 137 questions) and if the responses' count is less than 5 it makes the variable symis /blank. The problem with the existing syntax is that it is very lengthy . I want to run the syntax in loop . I write the looping code but it is not working ..No error coming but transformation pending. LOOPING SYNTAX : VECTOR Count_Q=Count_Q1 TO Count_Q137. FOR #I= 1 TO 137. DO IF (Count_Q(#I) < 5). comp P6_0001 = $sysmis. comp P5_0001 = $sysmis. comp P4_0001 = $sysmis. comp P3_0001 = $sysmis. comp P2_0001 = $sysmis. comp P1_0001 = $sysmis. comp Mean_0001 = $sysmis. END IF. END LOOP. EXISTING SYNTAX (WITHOUT LOOPING). **FOR Q1. DO IF (Count_Q1 < 5). comp P6_0001 = $sysmis. comp P5_0001 = $sysmis. comp P4_0001 = $sysmis. comp P3_0001 = $sysmis. comp P2_0001 = $sysmis. comp P1_0001 = $sysmis. comp Mean_0001 = $sysmis. END IF. **FOR Q2. DO IF (Count_Q2 < 5). comp P6_0001 = $sysmis. comp P5_0001 = $sysmis. comp P4_0001 = $sysmis. comp P3_0001 = $sysmis. comp P2_0001 = $sysmis. comp P1_0001 = $sysmis. comp Mean_0001 = $sysmis. END IF. .. Same code till Q137. As i am new to looping and vector please review my created syntax and correct if if wrong or suggest better way to do the same . Thanks in advance ! -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/looping-tp5583668p5583668.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
|
In reply to this post by Maguin, Eugene
"I just don't understand what you are doing."
DITTO!!! Please back up two or three steps and explain where the Mean_#### and P1_#### to P6_#### come from and *WHAT* you want to do *NOT* HOW you want to do it! What do you begin with prior to the mayhem and what do you want to result? Maybe the simple Mean.5 function requires exploration?
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 Sandy
I am extremely sorry to say i put wrong request ..p1_0001 to p6_0001 - p1_0137 to p6_0137 would be my variables and i found the solution to resolve my problem..I need to create multiple vectors for the same...
I am right ?? |
In reply to this post by Sandy
I agree that what you are trying to do seems to be wrong.
And it probably fails to run because you don't have any procedure or EXE to cause it to run. Here is a shorter way to do what your syntax specifies. You are setting to zero a half dozen scores whenever it happens that any single one of the 137 COUNT_Q's are less than 5. SO: Find out if there are any, by Counting how many there are. COUNT Lowcount= count_q1 to count_q137(0,1,2,3,4). DO IF lowcount NE 0. comp P6_0001 = $sysmis. comp P5_0001 = $sysmis. comp P4_0001 = $sysmis. comp P3_0001 = $sysmis. comp P2_0001 = $sysmis. comp P1_0001 = $sysmis. comp Mean_0001 = $sysmis. END IF. I doubt if that is what you really want to do. I think that RECODE can follow DO IF; in which case, you can use one RECODE instead of seven lines, setting (ELSE= $sysmis). -- Rich Ulrich > Date: Wed, 21 Mar 2012 10:59:28 -0700 > From: [hidden email] > Subject: looping > To: [hidden email] > > Hi All, > > I have syntax that count the responses for each questions (total 137 > questions) and if the responses' count is less than 5 it makes the variable > symis /blank. > > The problem with the existing syntax is that it is very lengthy . I want to > run the syntax in loop . I write the looping code but it is not working ..No > error coming but transformation pending. > > LOOPING SYNTAX : > > VECTOR Count_Q=Count_Q1 TO Count_Q137. > > FOR #I= 1 TO 137. > > DO IF (Count_Q(#I) < 5). > > comp P6_0001 = $sysmis. > > comp P5_0001 = $sysmis. > > comp P4_0001 = $sysmis. > > comp P3_0001 = $sysmis. > > comp P2_0001 = $sysmis. > > comp P1_0001 = $sysmis. > > comp Mean_0001 = $sysmis. > > END IF. > END LOOP. > > EXISTING SYNTAX (WITHOUT LOOPING). > > **FOR Q1. > > DO IF (Count_Q1 < 5). > > comp P6_0001 = $sysmis. > > comp P5_0001 = $sysmis. > > comp P4_0001 = $sysmis. > > comp P3_0001 = $sysmis. > > comp P2_0001 = $sysmis. > > comp P1_0001 = $sysmis. > > comp Mean_0001 = $sysmis. > > END IF. > > **FOR Q2. > > DO IF (Count_Q2 < 5). > > comp P6_0001 = $sysmis. > > comp P5_0001 = $sysmis. > > comp P4_0001 = $sysmis. > > comp P3_0001 = $sysmis. > > comp P2_0001 = $sysmis. > > comp P1_0001 = $sysmis. > > comp Mean_0001 = $sysmis. > > END IF. > > .. > > Same code till Q137. > > As i am new to looping and vector please review my created syntax and > correct if if wrong or suggest better way to do the same . > > Thanks in advance ! |
In reply to this post by Sandy
Yes, that makes an extraordinary difference. So a better explanation is that you have count_q1 to count_q137 and for each count_q(i) you have p1_(i) to p6_(i). And that if count_q(i) < 5, then p1_(i) to p6_(i), mean_(i)=sysmis.
I'm pretty sure you can do this with a macro but you'd have to call it 137 times. Not so nice. The most compact method would be this sort of syntax--given that the variables are arranged properly. Vector cc= count_q1 to count_q137/p=p1_1 to mean_137. Loop #i=1 to 137 Do if (cc(i) lt 5). + loop #j=1 to 7. + compute p((#i-1)*7+#j)=$sysmis. + end loop. End if. End loop. I understand sas will support this but I don't believe spss will. The step down (again given that the variables are arranged properly) is this. Vector cc= count_q1 to count_q137/p1=p1_1 to p1_137/p2=p2_1 to p2_137/p3=p3_1 to p3_137/p4=p4_1 to p4_137/ P5=p5_1 to p5_137/p6=p6_1 to p6_137/mn=mean_1 to mean_137. Loop #i=1 to 137 Do if (cc(i) lt 5). + compute p1(#i)=$sysmis. + compute p2(#i)=$sysmis. + compute p3(#i)=$sysmis. + compute p4(#i)=$sysmis. + compute p5(#i)=$sysmis. + compute p6(#i)=$sysmis. + compute mn(#i)=$sysms. End if. End loop. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Sandy Sent: Wednesday, March 21, 2012 2:46 PM To: [hidden email] Subject: Re: looping I am extremely sorry to say i put wrong request ..p1_0001 to p6_0001 - p1_0137 to p6_0137 would be my variables and i found the solution to resolve my problem..I need to create multiple vectors for the same... I am right ?? -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/looping-tp5583668p5583773.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 Maguin, Eugene
I can't speak for Sandy, but have a similar (conceptual) syntax to this. We have a database that takes in the survey data, and there is no cleaning on the backend, in order to match the cleaning process between paper and online. One of our cleaning criteria is that if anyone indicated doing a behavior in the last week, but then said they didn't do it in the last year, we sysmis the statements for the last week behavior, as we assume they aren't giving reliable information, and if they used in the last week, then they must have used in the last year. Similarly, for paper based surveys with skip patterns, if the participant didn't skip correctly, we will sysmis all the responses within a skip pattern in the event that they indicated in the earlier question something that should have had them skip the rest.
I wonder if what Sandy is doing is something similar. If a response item or variable indicator is below this threshold, they don't want to use or analyze any of the other data, and thus turn it to sysmis. As for the mean variable. If that variable is created from the other variables, unless this is a secondary analysis and the variables are already created, I would modify the protocol so that no variable is created for a row that should not have that mean. We do this by turning all response variables to sysmis which fail some criteria. So if we had a bunch of drug usage variables, and we wanted the average usage across drugs for the last 30 days, but the responses were irrational, then they would be set to sysmis, and the syntax for creating the mean (mean.5(var1,var2,var3,var4,var5)) would not create a mean for those cases. In my opinion, that is a better practice when possible (Don't create (even temporarily) a variable which goes against your validation criteria). Matthew J Poes Research Data Specialist Center for Prevention Research and Development University of Illinois 510 Devonshire Dr. Champaign, IL 61820 Phone: 217-265-4576 email: [hidden email] -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Maguin, Eugene Sent: Wednesday, March 21, 2012 1:13 PM To: [hidden email] Subject: Re: looping Sandy, I'm very confused by your non-looping syntax. It looks like that you have these 137 variables, count_q1 to count_q137, and then you have these other 7 variables, p1_0001 to p6_0001 and mean_0001, and if any of count_q1 to count_q137 are less than 5 you sysmis out p1_0001 to p6_0001, mean_0001. I just don't understand what you are doing. How does p1_0001 to p6_0001 and mean_0001 relate to count_q1 to count_q137 and why do you cycle through p1_0001 to p6_0001, mean_0001 137 times? I think we need to understand this part first. Gene Maguin -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Sandy Sent: Wednesday, March 21, 2012 1:59 PM To: [hidden email] Subject: looping Hi All, I have syntax that count the responses for each questions (total 137 questions) and if the responses' count is less than 5 it makes the variable symis /blank. The problem with the existing syntax is that it is very lengthy . I want to run the syntax in loop . I write the looping code but it is not working ..No error coming but transformation pending. LOOPING SYNTAX : VECTOR Count_Q=Count_Q1 TO Count_Q137. FOR #I= 1 TO 137. DO IF (Count_Q(#I) < 5). comp P6_0001 = $sysmis. comp P5_0001 = $sysmis. comp P4_0001 = $sysmis. comp P3_0001 = $sysmis. comp P2_0001 = $sysmis. comp P1_0001 = $sysmis. comp Mean_0001 = $sysmis. END IF. END LOOP. EXISTING SYNTAX (WITHOUT LOOPING). **FOR Q1. DO IF (Count_Q1 < 5). comp P6_0001 = $sysmis. comp P5_0001 = $sysmis. comp P4_0001 = $sysmis. comp P3_0001 = $sysmis. comp P2_0001 = $sysmis. comp P1_0001 = $sysmis. comp Mean_0001 = $sysmis. END IF. **FOR Q2. DO IF (Count_Q2 < 5). comp P6_0001 = $sysmis. comp P5_0001 = $sysmis. comp P4_0001 = $sysmis. comp P3_0001 = $sysmis. comp P2_0001 = $sysmis. comp P1_0001 = $sysmis. comp Mean_0001 = $sysmis. END IF. .. Same code till Q137. As i am new to looping and vector please review my created syntax and correct if if wrong or suggest better way to do the same . Thanks in advance ! -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/looping-tp5583668p5583668.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 |
Administrator
|
In reply to this post by Sandy
Not necessarily ;-) In fact *NO* vectors are required at all.
I am assuming you variables P1_####... P6_#### are contiguous permitting say P1_0001 TO P6_0001 to be valid. In which case the following macro sorts the situation. DEFINE BlastAway (K !TOKENS(1)). !DO !I=1 !TO !K. !LET !SUF="" !DO !J=!LENGTH(!I) !TO 3 !LET !SUF=!CONCAT(!SUF,0) !DOEND DO IF !CONCAT(Count_Q,!I) < 5. + DO REPEAT V=!CONCAT(P1_,!SUF,!I) TO !CONCAT(P6_,!SUF,!I) !CONCAT(Mean_,!SUF,!I). + COMPUTE V=$SYSMIS. + END REPEAT. END IF. !DOEND !ENDDEFINE. SET MPRINT ON. BlastAway K=137.
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
"I understand sas will support this but I don't believe spss will. "
I don't see any part of this that SPSS doesn't support. + compute p((#i-1)*7+#j)=$sysmis. is perfectly valid. I do it all the time. OTOH a simple amendment (changed p1_1 and cc(i) ) ASSUMES variables are in the following order P1_0001, P1_0002... P1_0006 Mean_0001, P2_0001 .... etc... Vector cc= count_q1 to count_q137/p=p1_0001 to mean_0137. Loop #i=1 to 137 Do if (cc(#i) lt 5). + loop #j=1 to 7. + compute p((#i-1)*7+#j)=$sysmis. + end loop. End if. End loop. "I'm pretty sure you can do this with a macro but you'd have to call it 137 times. Not so nice." Nah, see my posting 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
Another variation which does *NOT* require contiguous variable subsets: -- DEFINE Blastx (K !TOKENS(1) / Q !TOKENS(1)). !DO !I=1 !TO !K. !LET !SUF="" !DO !J=!LENGTH(!I) !TO 3 !LET !SUF=!CONCAT(!SUF,0) !DOEND !LET !SUF=!CONCAT(!SUF,!I) DO IF !CONCAT(Count_Q,!I) < 5. + DO REPEAT V=!DO !J=1 !TO !Q !CONCAT(P,!J,_,!SUF) !DOEND !CONCAT(Mean_,!SUF). + COMPUTE V=$SYSMIS. + END REPEAT PRINT. END IF. !DOEND !ENDDEFINE. SET MPRINT ON. BlastX K=137 Q=6.
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 Maguin, Eugene
Thanks a lot for help !
I am using the below code and it is not throwing any error but code not working . My Variables are in the order N1 to N137 p1_1 to p1_137 p2_1 to p2_137 p3_1 to p3_137 p4_1 to p4_137 p5_1 to p5_137 p6_1 to p6_137 p6_ecomp p5_ecomp p4_ecomp p3_ecomp p2_ecomp p1_ecomp. VECTOR N=N1 TO N137 /P1=p1_1 to p1_137 /P2=p2_1 to p2_137/P3=p3_1 to p3_137/P4=p4_1 to p4_137/P5=p5_1 to p5_137/P6=p6_1 to p6_137/Mean=Mean_1 to Mean_137. LOOP #I=1 TO 137. DO IF (N(#I) lt 5). comp P6(#I) = $sysmis. comp P5(#I) = $sysmis. comp P4(#I) = $sysmis. comp P3(#I) = $sysmis. comp P2(#I) = $sysmis. comp P1(#I) = $sysmis. comp Mean(#I) = $sysmis. comp N(#I) = $sysmis. END IF. END LOOP. |
Administrator
|
Sandy,
By "not working" I ESPss-uppose you mean that the visible content of the data editor do not reflect the results of the submitted data transformations. You need to add EXECUTE or even better some sort of procedure to get SPSS to read the data and update the contents of the fields. I surely hope you are saving this to a new data file (it is dangerous to overwrite existing data without complete verification that all went as hoped). HTH, David --
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 |