BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tomcmacdonald
Quartz | Level 8

SAS code looks like this:

 

data foo;
    input id a date10.;
    datalines;
1 '1Jan2017'd
2 '2Jan2017'd
3 '1Jan2006'd
4 '31Dec2006'd
;
run;

ods excel file=&file;

proc print data=foo noobs;
  var a / style(data)={tagattr='type:DateTime'};
run;

ods excel close;

In the Excel file field a is treated as a string instead of a date.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Apply a format to the date. It currently doesn't have one assigned, even in the SAS data set it looks like a numeric value.

View solution in original post

5 REPLIES 5
Reeza
Super User

Apply a format to the date. It currently doesn't have one assigned, even in the SAS data set it looks like a numeric value.

tomcmacdonald
Quartz | Level 8
I thought SAS treated dates as numeric and there is no date datatype. Shouldn't it really be date or datetime informats because that's how this numeric value is represented?
Reeza
Super User

INFORMATS control how SAS reads in a variable.

FORMATS control how SAS displays a variable. 

 

There is no date data type, but there are date formats, a numeric variable with a date format will be treated as a date in Excel. If you want Excel to recognize it as a date use the mmddyy10. format. 

 


@tomcmacdonald wrote:
I thought SAS treated dates as numeric and there is no date datatype. Shouldn't it really be date or datetime informats because that's how this numeric value is represented?

 

tomcmacdonald
Quartz | Level 8
OK, thank you.
Tom
Super User Tom
Super User

Huh? First thing is to make it look like a date to SAS before sending it to Excel.

 

data foo;
  input id a date9.;
  format a date9. ;
datalines;
1 01Jan2017
2 02Jan2017
3 01Jan2006
4 31Dec2006
;

Now try exporting using PROC PRINT.

 

 

ods excel file="&path/test_date.xlsx";

proc print data=foo noobs;
run;

ods excel close;

Looks fine to me.

image.png

 

 

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
  • 5 replies
  • 2239 views
  • 1 like
  • 3 in conversation