sasmacrosspss

creating a variable, SPSS Macros vs SAS


been programming in SAS for 14 year and just jumped into SPSS.

In SAS you can combine a macro call and a text string very easily using a period.

i.e.

%let name = ted ;

data work1 ;
var = &name._is_fun ;
run ;

var would resolve to ted_is_fun

I cannot for the life of me figure out how to do this simply in SPSS.

Thanks for the help, My First post!

Mark


Solution

  • Here's a way to do this type of thing with SPSS macro (look up define - !enddefine in the documentation):

    define !name(!pos=!tokens(1)) !concat("ted",!1) !enddefine.
    

    This is a definition of a macro called !name which accepts one token after the macro call and concatenates it to the word "ted".

    Now you're all set, you can call the macro this way for example:

    frequencies !name _is_fun .
    

    (this will be interpreted as frequencies ted_is_fun .