• How to use a variabe value to name a file using SPSS syntax?

    From tempjpw@gmail.com@21:1/5 to All on Mon Jul 29 12:26:35 2019
    I have a data set with 100+ variables for each of many people.

    I have two variables for the person's name: lastname and firstname.

    How can I create an output file using the names (i.e., the values of the variables lastname and firstname)?

    I would like to do a split file by lastname firstname and export the data for each person into a text file that uses the person's name as the file name.

    Any help will be greatly appreciated.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bruce Weaver@21:1/5 to tem...@gmail.com on Mon Jul 29 13:42:13 2019
    On Monday, July 29, 2019 at 3:26:36 PM UTC-4, tem...@gmail.com wrote:
    I have a data set with 100+ variables for each of many people.

    I have two variables for the person's name: lastname and firstname.

    How can I create an output file using the names (i.e., the values of the variables lastname and firstname)?

    I would like to do a split file by lastname firstname and export the data for each person into a text file that uses the person's name as the file name.

    Any help will be greatly appreciated.


    Readers should note that the same question was posted to the SPSSX-L forum. That thread can be viewed here:

    http://spssx-discussion.1045642.n5.nabble.com/How-to-use-a-variabe-value-to-name-a-file-using-SPSS-syntax-td5738204.html

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bruce Weaver@21:1/5 to tem...@gmail.com on Mon Jul 29 13:28:23 2019
    On Monday, July 29, 2019 at 3:26:36 PM UTC-4, tem...@gmail.com wrote:
    I have a data set with 100+ variables for each of many people.

    I have two variables for the person's name: lastname and firstname.

    How can I create an output file using the names (i.e., the values of the variables lastname and firstname)?

    I would like to do a split file by lastname firstname and export the data for each person into a text file that uses the person's name as the file name.

    Any help will be greatly appreciated.



    1. Check to see if you have the SPSSINC SPLIT DATASET extension command installed. If it is installed, you should see "Split into Files" as an option in the Data menu.

    2. If it is not installed, click Extensions > Extension Hub. Then search on the word SPLIT and follow the instructions to install SPSSINC_SPLIT_DATASET.

    3. Then do something like the following:

    * Data > Split into Files.
    SPSSINC SPLIT DATASET SPLITVAR=lastname firstname
    /OUTPUT DIRECTORY= "C:\Temp" DELETECONTENTS=NO
    /OPTIONS NAMES=VALUES.

    Change the DIRECTORY setting as needed.

    Here's an example I just tried using one of the sample datasets that comes with SPSS.

    * Use car_sales data to illustrate.
    * Change path on next line if necessary.
    GET FILE "C:\SPSSdata\car_sales.sav".
    * Make variable names match wht OP has.
    RENAME VARIABLES ( manufact model = lastname firstname).

    * Data > Split into Files.
    SPSSINC SPLIT DATASET SPLITVAR=lastname firstname
    /OUTPUT DIRECTORY= "C:\Temp" DELETECONTENTS=NO
    /OPTIONS NAMES=VALUES.

    This code generated 157 separate data files in my C:\Temp folder, one for each row in the original dataset (where there was one row for each lastname/firstname combination). Here are the first several file names:

    Acura_CL.sav
    Acura_Integra.sav
    Acura_RL.sav
    Acura_TL.sav
    Audi_A4.sav
    Audi_A6.sav
    Audi_A8.sav
    BMW_323i.sav
    BMW_328i.sav
    BMW_528i.sav

    etc.

    HTH.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)