Joel W.
Joel W.

Reputation: 111

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

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.

Below is what my spss command file is doing now. How can I get the command file to spit out separate files for each person?

SORT CASES BY lastname firstname .

SPLIT FILE BY lastname firstname .

PRINT / "    ".
PRINT /
"===================================================================".
PRINT / "Report of Selected Responses from the".
PRINT / "Survey Form Document".
Print /"Responses for Candidate: " .
Print / firstname.
Print / lastname.
PRINT /
"===================================================================".

DO IF (Q1.5month EQ "" OR sysmis(q1.5day) OR sysmis(q1.5year) ). 
Print
/ "1.5.  Some or all of date of birth left blank".
END IF.

[More such print statements.]

EXECUTE.
SPLIT FILE OFF.

Upvotes: 1

Views: 323

Answers (1)

horace_vr
horace_vr

Reputation: 3176

First create an empry string variable and populate it:

String firstname_lastname (A100). Compute firstname_lastname=concat(rtrim(firstname),"_",rtrim(lastname)). EXECUTE.

Then go to Data menu, Split into files, select your new firstname_lastname variable as the split variable, and.under options select "value labels". Pick a folder and you are done. Maybe click paste, to have everything in syntax 😉

Upvotes: 2

Related Questions