DATA Step, Macro, Functions and more

convert SAS to SPSS, taking labels and formats

Reply
Occasional Contributor
Posts: 6

convert SAS to SPSS, taking labels and formats

Hi

I need to convert some SAS data sets into SPSS data sets.  The SAS data set have labels and formats and some variables have long variable name (>8 characters).  My clients wants the data for SPSS with corresponding labels and formats.

I was adapting the code from this website (http://www.runsubmit.com/questions/240/convert-data-from-from-sas-to-spss-using-sas ) but I am hitting problems when trying to create a transport file of the SAS data set, due to longer variable name lengths.

Does anyone know how I can do it without having to rename variables in the data sets?

:smileyinfo: I am using SAS v9.3 (64-bit), need to convert for SPSS v20.

Thanks

Peta

Super User
Super User
Posts: 6,498

Re: convert SAS to SPSS, taking labels and formats

Personally I use STAT/Transfer.

You probably do NOT want to use SAS version 5 transport files as those will be limited to 8 character variable names and maximum length of 200 for character variables.

If you are desperate and know SPSS syntax well enough just get the variable names from the SAS metadata (or use PROC CONTENTS OUT=) and generate the SPSS code to read from a CSV file.  As the thread you link noted you can get the "value labels" of user defined formats using the CNTLOUT option on PROC FORMAT and use those to generate SPSS code.

Occasional Contributor
Posts: 6

Re: convert SAS to SPSS, taking labels and formats

Thanks Tom for your reply.  Just before I received your reply, I had figured it out (well, one way of doing it)

Step 1 : create a data set from the formats catalog

LIBNAME FMTDIR "C:\DATA - FINAL\FMTDIR";

LIBNAME LIBRARY "C:\DATA - FINAL\FMTDIR";

PROC FORMAT LIBRARY=LIBRARY.FORMATS  CNTOUT=FMTDIR.FMT_DATA; RUN;

Step 2 : export to an .SAV file using the FMTLIB option in the PROX EXPORT procedure (using the formats data set)

LIBNAME FMTDIR "C:\DATA - FINAL\FMTDIR";

LIBNAME DIR1 "C:\DATA - FINAL";

PROC EXPORT

  DATA= DIR1.SAS_DATA_1  OUTFILE= "C:\SPSS_DATA_1.SAV"  DBMS=SPSS REPLACE ;

  FMTLIB=FMTDIR.FMT_DATA;

  RUN;

This seems to have worked okay - longer variable name lengths preserved, formats/values exported into the SPSS file, etc.

Ask a Question
Discussion stats
  • 2 replies
  • 1701 views
  • 2 likes
  • 2 in conversation