SPSS Statistics

 View Only
  • 1.  syntax question

    Posted Thu August 04, 2022 08:32 AM
    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
    ------------------------------

    #SPSSStatistics


  • 2.  RE: syntax question

    IBM Champion
    Posted Thu August 04, 2022 08:47 AM
    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 Thu August 04, 2022 09:15 AM
    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

    IBM Champion
    Posted Thu August 04, 2022 09:23 AM
    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 3 days ago
      |   view attached

    I am having a very difficult time, a long time SPSS user but not in using syntax, and at my new job I will need to do so to create a random sample from a large excel data set of about 7k names.

    I attached the SPSS syntax file and the sampling procedure for what I need in case you can offer advice. 

    Thanks so much for being so helpful. At 63 I am still learning but the pace for me to learn this for my new job, is grueling.



    ------------------------------
    barry davis
    ------------------------------

    Attachment(s)

    docx
    sampling procedure.docx   14 KB 1 version


  • 6.  RE: syntax question

    Posted Fri August 05, 2022 07:27 AM
    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.







  • 7.  RE: syntax question

    Posted Fri August 05, 2022 09:05 AM
    Thanks.

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