How can I loop through variables in SPSS? I want to avoid code duplication

后端 未结 7 1695
失恋的感觉
失恋的感觉 2021-01-03 02:31

Is there a \"native\" SPSS way to loop through some variable names? All I want to do is take a list of variables (that I define) and run the same procedure for them:

<
7条回答
  •  耶瑟儿~
    2021-01-03 03:01

    If I understand the question correctly, there may be no need to use a looping construct. SPSS commands with a VARIABLES subcommand like FREQUENCIES allow you to specify multiple variables.

    The basic syntax for the FREQUENCIES is:

    FREQUENCIES
        VARIABLES= varlist [varlist...] 
    

    where [varlist] is a single variable name, multiple space-delimited variable names, a range of consecutive variables specified with the TO keyword, the keyword ALL, or a combination of the previous options.

    For example:

    FREQUENCIES VARIABLES=VARA
    
    FREQUENCIES VARIABLES=VARA VARB VARC
    
    FREQUENCIES VARIABLES=VARA TO VARC     
    
    FREQ VAR=ALL
    
    FREQ VAR=VARA TO VARC VARM VARX TO VARZ
    

    See SPSS Statistics 17.0 Command Syntax Reference available at http://support.spss.com/ProductsExt/SPSS/Documentation/SPSSforWindows/index.htm

    Note that it's been years since I've actually used SPSS.

提交回复
热议问题