Discussion:
How to use a variabe value to name a file using SPSS syntax?
(too old to reply)
t***@gmail.com
2019-07-29 19:26:35 UTC
Permalink
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.
Bruce Weaver
2019-07-29 20:28:23 UTC
Permalink
Post by t***@gmail.com
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.
Bruce Weaver
2019-07-29 20:42:13 UTC
Permalink
Post by t***@gmail.com
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
Loading...