I am trying to tweak some code found on Raynald's SPSS Tools website.
=====================
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
Thanks to David Marso for originally posting this on 3/24/88. Here is the link: http://spsstools.net/en/syntax/477/ __ I am trying to find the maximums and their location for a vector. I am trying to incorporate a cut-off. For example, I not only want to--rank order the variables in the vector and find their location in the vector--but I want them to be above a certain threshold (e.g., 52). Here is the syntax I use to recode the vector into a value if the value is below a certain cutoff: VECTOR CUTOFF = x1 TO x10. LOOP #I = 1 to 10. DO IF (CUTOFF(#I)) LT 52. + COMPUTE CUTOFF(#I)=0. + END IF. END LOOP. EXECUTE. I also tried: + COMPUTE CUTOFF(#I)=$SYSMIS. My problem is that the WHERE vector is providing the appropriate location (i.e., doing what it is intended to do) when I want it to provide a static value for the location (e.g., 0), when the corresponding value is below the cut-off. Currently it is giving me this: WHERE1 WHERE2 WHERE3 2 4 7 1 1 1 6 9 1 5 1 2 I want it to give me this: WHERE1 WHERE2 WHERE3 2 4 7 0 0 0 6 9 0 5 1 0 If anyone had any help I would greatly appreciate it. Below is the code: data list free / x1 to x10. begin data. 13 54 23 54 25 12 52 3 51 23 15 41 23 15 42 31 23 12 15 12 51 43 51 36 12 53 6 12 53 12 63 51 23 51 73 51 35 12 35 35 end data. VECTOR CUTOFF = x1 TO x10. LOOP #I = 1 to 10. DO IF (CUTOFF(#I)) LT 52. + COMPUTE CUTOFF(#I)=0. + END IF. END LOOP. EXECUTE. ** TO GET MAXIMUMS AND THEIR LOCATION ** . VECTOR WHAT (3) / WHERE(3). loop #=1 to 3. COMPUTE WHAT(#)=MAX(X1 TO X10). COMPUTE #FOUND=0. DO REPEAT X=X1 to X10 / Ind = 1 TO 10. DO IF X=WHAT(#) AND NOT #FOUND. COMPUTE WHERE(#)=Ind. COMPUTE X=-X. COMPUTE #FOUND=1. END IF. END REPEAT. END LOOP. DO REPEAT X=X1 TO X10. IF X < 0 X=-X. END REPEAT. FORMATS ALL (F2.0). LIST. ___ Sincerely, Derek Mracek |
Administrator
|
No need to clobber the original data values ;-) Just stick the cutoff in the conditional check. Also changed the logic slightly to get loop to terminate immediately rather than DO REPEAT. HTH DATA LIST FREE / x1 to x10. BEGIN DATA. 13 54 23 54 25 12 52 3 51 23 15 41 23 15 42 31 23 12 15 12 51 43 51 36 12 53 6 12 53 12 63 51 23 51 73 51 35 12 35 35 END DATA. ** TO GET MAXIMUMS AND THEIR LOCATION ** . VECTOR WHAT (3) / WHERE(3)/X=X1 TO X10. RECODE Where1 TO Where3 (ELSE=0). LOOP #=1 to 3. + COMPUTE WHAT(#)=MAX(X1 TO X10). + COMPUTE #FOUND=0. + LOOP Ind =1 TO 10. + DO IF X(Ind)=WHAT(#) AND NOT (#FOUND) AND What(#) GE 52. + COMPUTE WHERE(#)=Ind. + COMPUTE X(Ind)=-X(Ind). + COMPUTE #FOUND=1. + END IF. + END LOOP IF #Found. END LOOP. DO REPEAT X=X1 TO X10. IF X < 0 X=-X. END REPEAT. FORMATS ALL (F2.0). LIST.
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 dmracek23
Looking at that date 1988 I am feeling REALLY OLD ;-)
It was actually 1998 (still that is 18 years almost to the day).
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
|
There's only one explanation, David: Obviously, you were a child prodigy. ;-)
--
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/). |
Thank you David! You are still as sharp as ever. This was very helpful. Derek On Tue, Mar 15, 2016 at 6:06 PM, Bruce Weaver <[hidden email]> wrote: There's only one explanation, David: Obviously, you were a child prodigy. |
Free forum by Nabble | Edit this page |