2
votes

As I am new to SAS I am having trouble to import spss data into sas using the "proc import" command. The code I was using:

proc import datafile = "C:\Users\spss.sav"
 out=work.test
 dbms = sav
 replace;
 run;

The main problem is that when imported to sas, the datatable variables have the values and not the coding. So for instance if the variable "Gender" is coded 1=male 2=female, each observation in sas has "female" or "male".

Now according to here:

Proc Import from SPSS

if the following code is added after the code above, then this problem ceases to exist:

proc datasets;
modify my_dataset;
format _all_;
quit;

What still remains is that the Variable names from spss, instead of having their name, when imported to sas they have the labels that are assigned in spss. Is there any command that can keep the Names of the variables in SAS, instead of the SPSS labels?

2
Note that your coding is actually there - if you have q1: 1=yes 2=no, and you say if q1=1 then ... it would work. The value labels (formats) are solely cosmetic (and same with the variable labels).Joe
Very interesting. I didn't know that I could still use the name of the variable in the syntax, even though only the label of the variable appears. Thanks for that. However, in my data-set the number of variables exceeds 1000. So it is impossible to remember the actual name of all the variables, and since the labels are too long, it is not convenient to use them in the syntax. Therefore I need to "switch" from showing the labels, to showing the names, without deleting the labels.Noob_Strider

2 Answers

3
votes

It's possible that you are seeing column labels but that the underlying names still exist. You can modify your datasets procedure to remove the labels as well as the formats. Try this after your proc import:

proc datasets library = work;
    modify test;
    attrib _ALL_ label = " " format =;
run;

The attrib statement is applying a blank label and format to every variable.

0
votes

I had a similar problem. I had yearly SPSS datasets for a survey and the same format, call it "Yearformat" would go 0=2011, 1=2012, ... for the 2011 data, but 0=2012, 1=2013, ..., for 2012 data, etc. It seems like there should be a better solution, but what I did was .. SPSS -> save as SAS 9 for windows.. and click the option to output the formats to a sas dataset and then applied / modified the formats as necessary along the way .. mainly data datacopy ; set data ; newyear = put(year,yearformat.) to preserve the proper years.

enter image description here

But the point is, SPSS will create a sas dataset without the formats and a script with the formats and code to apply/modify the dataset with those formats. So you have control over the process.