Topic
  • 2 replies
  • Latest Post - ‏2013-08-15T17:01:25Z by ValerieRoch
SantoshBS
SantoshBS
1 Post

Pinned topic Accessing nth case of a variable

‏2013-08-10T14:51:54Z |

Hi

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:
if(GroupID.12="123").....

Rgds
Santosh

  • JonPeck
    JonPeck
    263 Posts

    Re: Accessing nth case of a variable

    ‏2013-08-11T12:54:16Z  

    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.

    Updated on 2013-08-11T13:03:03Z at 2013-08-11T13:03:03Z by JonPeck
  • ValerieRoch
    ValerieRoch
    21 Posts

    Re: Accessing nth case of a variable

    ‏2013-08-15T17:01:25Z  

     

    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.

    END IF.

     

    AGGREGATE

       /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?