BookmarkSubscribeRSS Feed
Saugata
Obsidian | Level 7

Hi,

I am trying to create an EXCEL from sas dataset using ODBC. Everything works fine but when there are some formats (both system and user defined) present in the data it seems Excel is not able to interpret it correctly. Sometimes the values are going into excel instead of format. The below code will elaborate on my problem:

Proc Format;
Value $Daypart '1' ='Morning'
       '2' ='Daytime Weekdays'
       '3' ='Daytime Weekend'
       '4' ='Early Prime'
       '5' ='Peak Prime'
       '6' ='Late Prime'
       '7' ='Night';
Run;

Data Curve_info;
format Daypart $Daypart. date date9. time time8. ;

  input Daypart date  time;
   datalines;
1 19368 21600
4 19368 72000
5 19368 75600
6 19368 82800
;
run;

libname rfxls odbc noprompt="DBQ=C:\Excel_details.xls;

driver={microsoft excel driver (*.xls)}; readonly=0"
;

data rfxls.Sheet1;
set curve_info;
run;
libname rfxls clear;

I am getting the Excel_details.xls file as:

Daypartdatetime
11/10/20131/1/1960
41/10/20131/1/1960
51/10/20131/1/1960
61/10/20131/1/1960

One can see from here that the Daypart format is not there (only the numeric values), Date field is appearing in ddmmyy10. format instead of date9. and Time field is appearing completely wrong.

It seems that excel is only getting the values from SAS dataset and then applying it's own format according to its understanding.

Is there a way to keep the formats as it appears in sas into excel file using ODBC?

Thanks in advance for your help.

Regards,

Saugata Mukherjee.

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
  • 0 replies
  • 676 views
  • 0 likes
  • 1 in conversation