I am looking to access nth (say 12th) case's value for a variable (say GroupID). What is the syntax for the same?
The below throws an error:
Pinned topic Accessing nth case of a variable
JonPeck 270002VCWN269 Posts
Re: Accessing nth case of a variable2013-08-11T12:54:16ZThis is the accepted answer. This is the accepted answer.
You cannot access an absolute case number in traditional syntax, only cases numbers relative to the current case. You can use a lookup table on a dataset by using the SPSSINC TRANS extension command with the extendedTrans.vlookup function. These require the Python Essentials available via this site.
If you can describe at a higher level what you need to do, there might be another way to tackle the problem. Absolute case numbers are rarely needed.
ValerieRoch 270005JUNS20 Posts
Re: Accessing nth case of a variable2013-08-15T17:01:25ZThis is the accepted answer. This is the accepted answer.
I'm not sure why you want to do this. It seems strange. But, wouldn't something like the following work?
* Get a new variable that contains case 12's ID value. This variable will be set for every row.
STRING case_12_value (A3).
DO IF ($CASENUM = 12).
COMPUTE case_12_value = GroupID.
/OUTFILE = * MODE=ADDVARIABLES OVERWRITE=YES
/case_12_value = MAX(case_12_value).
* Now do the comparison for each row.
IF (case_12_value = '123') ....
It does seem unlikely that this is the most efficient way to accomplish whatever it is you want to do?