Search code examples
spss

Shortcuts for specifying multiple variables in SPSS


Are there any shortcuts codes in SPSS for listing multiple variables? Say something similar to v1-v3 instead of v1 v2 v3 in SAS data step?


Solution

  • Some commands allow you to use the TO modifier (but not all). This is dependent on variables being in correct order in the data matrix. There are also multiple response sets, and defining macro calls to a specific set of variables.

    Below I give examples of using TO and defining a set of variables via a macro. I admittedly never use multiple response sets, so I can only state it is an option (more useful for a set of dichotomous items than continuous variables I believe).

    set seed = 10.
    input program.
    loop #i = 1 to 100.
    compute id = #i.
    compute V1 = RV.NORM(0,1).
    compute V2 = RV.UNIFORM(0,1).
    compute V3 = RV.POISSON(3).
    compute V4 = RV.BERNOULLI(.5).
    compute V5 = RV.BINOM(5,.8).
    end case.
    end loop.
    end file.
    end input program.
    dataset name sim.
    execute.
    
    freq var V1 to V5 /format = notable /statistics = mean.
    
    DEFINE !myvars () V1 V2 V3 V4 V5.
    !ENDDEFINE.
    
    set mprint on.
    freq var !myvars /format = notable /statistics = mean.