SPSS Statistics

 View Only
  • 1.  syntax question

    Posted 12 days ago
    I need to stack a range of variables into one.  I'm trying to avoid pulling them out one by one and stacking them.  So below is what I'd like to avoid. 

    dataset close all.
    DATA LIST FREE/
    Time (a15) SR1 (a15) SR2 (a15) SR3 (a15) SR4 (a15).
    BEGIN DATA.
    time1 Y N Y Y
    time1 Y Y N Y
    time2 N N Y N
    time4 Y Y N N
    END DATA.
    save file='c:\temp.sav'.

    dataset close all.
    get file='c:\temp.sav' /keep time SR1 /rename sr1=sr.
    save file='c:\temp1.sav'.
    dataset close all.
    get file='c:\temp.sav' /keep time SR2 /rename sr2=sr.
    save file='c:\temp2.sav'.
    dataset close all.
    get file='c:\temp.sav' /keep time SR3 /rename sr3=sr.
    save file='c:\temp3.sav'.
    dataset close all.
    get file='c:\temp.sav' /keep time SR4 /rename sr4=sr.
    save file='c:\temp4.sav'.

    dataset close all.
    add files /file='c:\temp1.sav'
    /file='c:\temp2.sav'
    /file='c:\temp3.sav'
    /file='c:\temp4.sav'.
    execute.

    Is there a function that can combine SR1 to SR4 into SR?  Thanks. - Arthur


    ------------------------------
    Art Jack
    ------------------------------


  • 2.  RE: syntax question

    Posted 12 days ago
    You can use the RENAME subcommand on ADD FILES to make the SR variable names all the same, or you could use  the RENAME VARIABLES command to change the names each time you GET a file.

    Note that you can just assign dataset names when you read each file rather than saving the files and then use those names in your ADD FILES command.

    ------------------------------
    Jon Peck
    ------------------------------



  • 3.  RE: syntax question

    Posted 12 days ago
    Can you send me a short example of this?  Thanks Jon.

    "Note that you can just assign dataset names when you read each file rather than saving the files and then use those names in your ADD FILES command."

    ------------------------------
    Art Jack
    ------------------------------



  • 4.  RE: syntax question

    Posted 12 days ago
    get file=...
    rename variable (SR1 = SR).
    dataset name one.
    get file=...
    rename variable (SR2=SR).
    dataset name two.
    ,...
    add files /file=one /file=two.
    ...

    --





  • 5.  RE: syntax question

    Posted 11 days ago
    look into the command varstocases (see: https://www.spss-tutorials.com/spss-varstocases-what-and-why/). this should do it.
    Result SPSS VARSTOCASES - Wrong Results. In our second example, we placed two variables on top of each other in one new variable.Both input variables had a variable label but the (single) output variable can have only one variable label.



    This e-mail and any files transmitted with it may contain privileged or confidential information. It is solely for use by the individual for whom it is intended, even if addressed incorrectly. If you received this e-mail in error, please notify the sender; do not disclose, copy, distribute, or take any action in reliance on the contents of this information; and delete it from your system. Any other use of this e-mail is prohibited.


    Thank you for your compliance.







  • 6.  RE: syntax question

    Posted 11 days ago
    Thanks.

    ------------------------------
    Art Jack
    ------------------------------