BookmarkSubscribeRSS Feed
pmf007
Fluorite | Level 6

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

2 REPLIES 2
Tom
Super User Tom
Super User

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.

pmf007
Fluorite | Level 6

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 6723 views
  • 3 likes
  • 2 in conversation