OK, make your life simpler by reshaping the data from WIDE to LONG, sort the result then go back to wide (or NOT depending upon what you need to do later). I'm not going to try to debug your LOOP code when it is far more efficient to work with an appropriate data structure.
You could also read your data into MATRIX, use the GRADE function and remap the data. I posted such a solution last week or the week before (search the archives).
/* simulate some data */.
DATASET DECLARE raw.
MATRIX.
SAVE (TRUNC(UNIFORM(1000,227)*1000))/OUTFILE raw / VARIABLES var001 TO var227.
END MATRIX.
DATASET ACTIVATE raw .
COMPUTE ID=$CASENUM.
DATASET COPY copyraw.
DATASET ACTIVATE copyraw.
VARSTOCASES / MAKE var FROM var001 TO var227 / INDEX=INDVar(var).
SORT CASES BY ID (A) Var(D).
COMPUTE pos=NUMBER(CHAR.SUBSTR(IndVar,4),N3).
EXECUTE.
DELETE VARIABLES IndVar var .
CASESTOVARS / ID=ID.
MATCH FILES / FILE raw / FILE * / BY ID .
Alex Dima wrote
hi,
i'm trying to reorder a set of variables by their first found maximum score in the set.
there are 227 vars which store the scores and the outcome variables should be 227 (pos1 to pos227).
so for instance if var34, var60 and var100 have max score of 10 (all 3 variables) the outcome variables which show the order should have: pos1=34, pos2=60, pos3=100 etc.
i have written the below syntax but it seems that when the max value changes the loop stops.
any help is much appreciated.
vector pos(227).
vector a=pos1 to pos227.
vector v=var1 to var227.
comp c=0.
loop #i=1 to 227.
comp max=max(var1 to var227).
do if v(#i)=max.
comp c=c+1.
comp a(c)=#i.
comp v(#i)=$sysmis.
end if.
end loop.
exe.
Thank,
Alex
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?"