SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AWillems
Fluorite | Level 6

I tried to import a SPSS file into SAS, using this command:

 

proc import out = /new datafile in SAS/
datafile = "Location of original SPSS file";
dbms = SAV replace;
fmtlib = work.formats;

run;

Everything works out fine, except the predefined values in SPSS 66 'not applicable' and 88 'don't know' are changed into " . " missings.

 

Any suggestions?

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

I would suggest changing the SPSS data so that these values are not defined as "user missing values" in SPSS.  That should let SAS import them as numbers.  Then in SAS you can recode them to special missing values, .N .D etc.  My guess is PROC IMPORT doesn't have logic for converting SPSS user missing values into SAS special missing values, so it just converts all the SPSS user missing values to the default SAS missing value.   Since SPSS only allows 3 user-missing values per column, in theory PROC IMPORT could have been coded to convert the three values to .A .B and .C, but I'm guessing the PROC IMPORT developer didn't bother with that wrinkle.

 

Luckily, once you have the values in SAS, recoding them to special missing values with an array is straight forward.  And I would assume on the SPSS side it should be possible to loop through all your variables and remove the user-missing values.  But I haven't used SPSS in 27 years...

The Boston Area SAS Users Group is hosting free webinars!
Next up: SAS Trivia Quiz hosted by SAS on Wednesday May 21.
Register now at https://www.basug.org/events.

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

Did it create formats in the WORK.FORMATS catalog for any of those variables?

Can you provide a small example SAV file with just a couple of variables and a few observations that demonstrate the issue?

AWillems
Fluorite | Level 6

SAS creates a FORMATS catalog in my own created library (other than work).

I've created a subset of the sample. Variable 'hulpnood' refers to be in need of help. If a persons answers with 'no' all the other variables are not applicable (value 66) and not missing ( .  )

 

/* 1) Import SPSS datfile*/

proc import out = test_spss
datafile = "test_spss.sav"
dbms = sav
replace;
fmtlib = work.formats;
run;


proc datasets lib = work nolist nodetails;
contents data = test_spss;
quit;

 

proc print data= test_spss;
run;

 

Tom
Super User Tom
Super User

When I import that data NONE of the variables have ANY missing values.  Some of them do have the value 66.

Are you saying that PROC IMPORT has converted the 99's to 66's?

----------------------------------------------------------------------------
|       FORMAT NAME: PROF_HA  LENGTH:   14   NUMBER OF VALUES:    4        |
|   MIN LENGTH:   1  MAX LENGTH:  14  DEFAULT LENGTH:  14  FUZZ:        0  |
|--------------------------------------------------------------------------|
|START           |END             |LABEL  (VER. V7|V8   03SEP2021:08:48:41)|
|----------------+----------------+----------------------------------------|
|               0|               0|No                                      |
|               1|               1|Yes                                     |
|              66|              66|Not applicable                          |
|              99|              99|No answer                               |
----------------------------------------------------------------------------

                                           Cumulative    Cumulative
        prof_h    Frequency     Percent     Frequency      Percent
-------------------------------------------------------------------
No                       1       33.33             1        33.33
Not applicable           2       66.67             3       100.00

                                   Cumulative    Cumulative
prof_h    Frequency     Percent     Frequency      Percent
-----------------------------------------------------------
     0           1       33.33             1        33.33
    66           2       66.67             3       100.00

Quentin
Super User

I would suggest changing the SPSS data so that these values are not defined as "user missing values" in SPSS.  That should let SAS import them as numbers.  Then in SAS you can recode them to special missing values, .N .D etc.  My guess is PROC IMPORT doesn't have logic for converting SPSS user missing values into SAS special missing values, so it just converts all the SPSS user missing values to the default SAS missing value.   Since SPSS only allows 3 user-missing values per column, in theory PROC IMPORT could have been coded to convert the three values to .A .B and .C, but I'm guessing the PROC IMPORT developer didn't bother with that wrinkle.

 

Luckily, once you have the values in SAS, recoding them to special missing values with an array is straight forward.  And I would assume on the SPSS side it should be possible to loop through all your variables and remove the user-missing values.  But I haven't used SPSS in 27 years...

The Boston Area SAS Users Group is hosting free webinars!
Next up: SAS Trivia Quiz hosted by SAS on Wednesday May 21.
Register now at https://www.basug.org/events.
AWillems
Fluorite | Level 6
Thanks for the advice and it actually worked!

I've changed in the SPSS data set (variable view) the missing to none instead of 66, 88,... Now SAS reads all the values and doesn't convert all the SPSS missing values to the default SAS missing values (because there are no missing values any more)

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1796 views
  • 2 likes
  • 3 in conversation