|
Hi all
Max gives the highest number in a range of variables. Compute MaxNumber=max(var1 to var10). I'm looking for a neat way to determine the the 2nd & 3rd highest numbers as well. Any suggestions? -- Mark Webb Line +27 (21) 786 4379 Cell +27 (72) 199 1000 Fax to email +27 (86) 5513075 Skype webbmark Email [hidden email]===================== 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 |
|
Mark
freq var1 to var10
.
At least it doesn't waste paper these days, but if
you have hundreds of values you might get RSI scrolling down to find the last
three values in each of ten frequency counts! On second
thoughts:
freq var1 to var10 /for dfreq
.
. . . will save you scrolling. When you've
found the values you want, you can always use something like
count topthree = var1
to var10 (top1, top2, top3) .
I'm sure someone else will supply something more
effective, but also much more complex.
John Hall
|
|
Dear
list,
I'm
trying to do run the following macro:
DEFINE
!LOOP ( ) .
!DO !I
= 1 !TO 2 .
!DO !J
= 1 !TO I!*2 .
{CODE}
!DOEND
.
!DOEND
.
!ENDDEFINE .
!LOOP
.
When
running this, Loop !J ignores the multiplication by 2. Probably SPSS
sees everything behind the asterisk as comments so I tried
this:
DEFINE
!LOOP ( ) .
!DO !I
= 1 !TO 2 .
!LET
!END = !I * 2 .
!DO !J
= 1 !TO !END .
{CODE}
!DOEND
.
!DOEND
.
!ENDDEFINE .
!LOOP
.
But
this didn't work either because now I got an error message. Apparently SPSS sees
!END as a string and you can't loop over a string. Does anyone know how to solve
this problem? Thank you very much in advance!
Best
regards,
Joost
van Ginkel ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. **********************************************************************
|
|
In reply to this post by John F Hall
A simpler procedure than John's which generate less output
is:
desc var=var1 to var10/stat=MAX/sort=MAX(D).
The descriptives procedure about will provide one line of
output
for each variable and reorder the sequence of variables to
have
the variable with the greatest maximum value first, next
greatest
maximum value third, and so on.
But the original request was really for something
like
Compute Max1=max(var1 to var10). /* Greatest Maximum
value.
compute Max2=max2(var1 to var10. /* 2nd Greatest Max
value.
compute Max3=max3(var1 to var10). /*3rd Greatest Max
value
I think this requires one to be able to sort or rank the
values of
var1 to var10 for each subject which can probably be done
by
vectors and loops. Perhaps some interested SPSS syntax
writer
can work out the code (I'm a little busy right
now).
-Mike Palij
New York University
|
|
In reply to this post by Mark Webb-5
Using the SPSSINC TRANS extension command available from SPSS Developer Central (www.spss.com/devcentral) (just 5 variables in this example). SPSSINC TRANS applies the function f to all the cases, creating three new variables, v1, v2, v3. data list free/x1 to x5. begin data 1 3 5 7 9 9 8 7 6 5 1 4 10 -2 2 end data. begin program. import spss def f(x): return(sorted(x,reverse=True)[:3]) end program. spssinc trans result=v1 to v3 /formula "f([x1,x2,x3,x4,x5])". HTH, Jon Peck SPSS, an IBM Company [hidden email] 312-651-3435
Hi all Max gives the highest number in a range of variables. Compute MaxNumber=max(var1 to var10). I'm looking for a neat way to determine the the 2nd & 3rd highest numbers as well. Any suggestions? -- Mark Webb Line +27 (21) 786 4379 Cell +27 (72) 199 1000 Fax to email +27 (86) 5513075 Skype webbmark Email targetlinkmark@... ===================== 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 Joost van Ginkel
Hi Joost,
This is what I use:
/* Create empty data set with 1 case 1 var; needed in LOOPi */. INPUT PROGRAM. VECTOR V(1). LOOP #I = 1 TO 1. LOOP #J = 1 TO 1. END END CASE. END END FILE. END INPUT PROGRAM. execute. /* Define LOOPi Macro */. DEFINE LOOPi (). !DO !I = 1 !TO 2 . compute tmpval = !i * 2. write out='tmp.sav' /"define !loopjval() " tmpval " !enddefine.". exe. include file='tmp.sav' . /* Call LOOPj Macro */. Loopj loopjval = !loopjval. !DOEND . !ENDDEFINE . /* Define LOOPj Macro */. DEFINE LOOPj (loopjval = !TOKENS(1) ). !DO !J = 1 !TO !loopjval . !DOEND . !ENDDEFINE . /* Call LOOPi Macro */. LOOPi. From: SPSSX(r) Discussion on behalf of Ginkel, Joost van Sent: Thu 05-Aug-10 14:34 To: [hidden email] Subject: Problem with loops in macros Dear list,
I'm trying to do run the following macro:
DEFINE !LOOP ( ) .
!DO !I = 1 !TO 2 .
!DO !J = 1 !TO I!*2 .
{CODE}
!DOEND .
!DOEND .
!ENDDEFINE .
!LOOP .
When running this, Loop !J ignores the multiplication by 2. Probably SPSS sees everything behind the asterisk as comments so I tried this:
DEFINE !LOOP ( ) .
!DO !I = 1 !TO 2 .
!LET !END = !I * 2 .
!DO !J = 1 !TO !END .
{CODE}
!DOEND .
!DOEND .
!ENDDEFINE .
!LOOP .
But this didn't work either because now I got an error message. Apparently SPSS sees !END as a string and you can't loop over a string. Does anyone know how to solve this problem? Thank you very much in advance!
Best regards,
Joost van Ginkel ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. **********************************************************************
|
|
Administrator
|
In reply to this post by Mark Webb-5
For some BP solutions, see items 11 and 14 here: http://www.spsstools.net/SampleSyntax.htm#RankingLargestValuesSortingGrouping 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 Kooij, A.J. van der
|
|
Dear Albert-Jan,
Thank you! I will give that a try.
Best regards,
Joost From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Albert-Jan Roskam Sent: vrijdag 6 augustus 2010 10:14 To: [hidden email] Subject: Re: Problem with loops in macros
|
| Free forum by Nabble | Edit this page |
