Question

I have data inside SAS.

I want to store the datafile to SPSS format (*.sav)

I use the following program:

PROC export Data=SASdataToStoreInSPSS
FILE="Path\Filename_%sysfunc(today(),date9.).sav"
dbms=sav replace;
RUN;

This works great. Except when I open the file in SPSS the dates are strangly formatted.

For example:

156405 08:51:00

Should be

3-Jan-2011 08:51

I can manually change the data formats in SPSS. So the values are correct date values, except they are not automatically formatted in a readable format.

I tried to change the format in SAS before saving to DATETIME20. or DATETIME23.3. But this does not help.

I want this to work without having to open SPSS and run a Syntax there. The SPSS files that SAS spits out have to be directly mailed to other users of the data.

Was it helpful?

Solution 2

SAS mentioned it has to do with the SPSS driver they use. Apparently it is not an easy fix so they forwarded the issue to second-line tech support.

The workaround you will need is split the dates in two columns. One with date and one with time.

data SPSS2;
set SPSS;

date = put(datepart(DatumSPSS), date9.); 
time = put(timepart(DatumSPSS), time8.); 
run;

Or you can tell the end user how to change the format of the date in SPSS.

OTHER TIPS

I think this is either a bug with SAS's export, or an issue with SPSS where some default changed. What's happening is that SAS is storing it as a SPSS Date - but with width 16, which is not long enough to hold the complete datetime. I don't think you can use DBDSOPTS with DBMS=SPSS, so I don't know that there is a good workaround short of importing the file into SPSS.

You could do that automatically, though, using the SPSS Production facility; I've written an import script before and asked SAS to run spssprod with the batch file. That's an irritating workaround, but it might be the easiest, unless SAS Tech Support can help you (and certainly try that - they are usually only a few hours' turnaround for initial contact at least).

For an automated approach, try this .NET app. You need SPSS, but SAS is not required to convert a large collection of SAS files automatically. Manual Process included code samples or Application Download

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top