Reputation: 11
1) I need SPSS to return the variable name of the highest variable in a series of subscales. Basically I have ten subscales with mean scores ranging from 0 to 5, I don't want to know the highest score for each case, but rather which subscale is highest.
When I use this syntax, I just get the score, which doesn't tell me which category it belongs to.
COMPUTE Motivation_Highest2 = MAX(Stress_Mgmt, Revitalisation, Enjoyment, Challenge, SocialRecog, Affiliation, Competition, HealthPress, IllHealth, PosHealth,
WtMgmt, Appearance, StrengthEnd, Nimbleness, MotivationHighest).
VARIABLE LABELS Motivation_Highest2 'Motivation Intensity: Highest Score on any Motivation Subscale'.
EXECUTE.
Can I ask SPSS to return the variable name instead of the score?
2) There may be two scores that are both equally high. In this case, I would like SPSS to give me both variable names.
Thanks!
Upvotes: 1
Views: 1096
Reputation: 5089
This is an ok job for a macro to do.
DEFINE !MaxVars (OutN = !TOKENS(1)
/OutV = !CHAREND("/")
/Var = !CMDEND)
NUMERIC !OutN.
!DO !I !IN (!Var)
COMPUTE !OutN = MAX(!OutN,!I).
!DOEND
STRING !OutV (!CONCAT("A",!LENGTH(!Var))).
!DO !I !IN (!Var)
IF !I = !OutN !OutV = LTRIM(CONCAT(RTRIM(!OutV)," ",!QUOTE(!I))).
!DOEND
!ENDDEFINE.
And here is an example of using it on a set of data.
DATA LIST FREE / X1 X2 X3.
BEGIN DATA
1 2 3
3 2 1
4 4 0
0 4 4
1 1 1
END DATA.
!MaxVars OutN = Max OutV = Vars /Var = X1 X2 X3.
If you then run LIST Max Vars.
it will return in the output:
Max Vars
3 X3
3 X1
4 X1 X2
4 X2 X3
1 X1 X2 X3
Upvotes: 1