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

Hello,

 

Nice to meet everyone here. It's my first time to use sas. And I am facing a big prolem now.

I want to export my sas data to excel, and it worked. But the only problem is that my format of date is not correct! But it's correct when I viewed on the sas...I don't know what's wrong with it...

 

Please help me. Thanks a lot!

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

How do you export to Excel? 

 

In SAS a date value is stored as a number in a variable of type numeric (there is no type 'date' like in other languages). You then apply a so-called SAS Format to this variable so it "prints" formatted showing a date string.

 

SAS dates are stored as the number of days since 1Jan1960. Normally when a date format has been assigned to a numeric variable SAS converts the value to the appropriate form required by Excel. It appears this hasn't worked for you and you've got instead the internal numeric values as numbers.

 

One reason why this could have happened: The date format applied on your SAS dataset has not been an OOTB one. To test the theory you could do the following:

1: Apply a standard SAS date format to your variables (in below code replace "my_dataset" with the name of your real data set).

data want;
  set my_dataset;
  format date exci_date date9.;
run;

2. Download the "want" dataset.

 

 

 

View solution in original post

3 REPLIES 3
Loko
Barite | Level 11

Hello,

 

In SAS date is a number, you only see it as a date because you formatted the number as a date.

One solution may be to transform the number in text using put function (newvar=put(oldvar, date9.) and export the new text variable.

 

 

Ariel
Calcite | Level 5
Hello,
Thank you for your recommendation. I finally finished it 🙂
Patrick
Opal | Level 21

How do you export to Excel? 

 

In SAS a date value is stored as a number in a variable of type numeric (there is no type 'date' like in other languages). You then apply a so-called SAS Format to this variable so it "prints" formatted showing a date string.

 

SAS dates are stored as the number of days since 1Jan1960. Normally when a date format has been assigned to a numeric variable SAS converts the value to the appropriate form required by Excel. It appears this hasn't worked for you and you've got instead the internal numeric values as numbers.

 

One reason why this could have happened: The date format applied on your SAS dataset has not been an OOTB one. To test the theory you could do the following:

1: Apply a standard SAS date format to your variables (in below code replace "my_dataset" with the name of your real data set).

data want;
  set my_dataset;
  format date exci_date date9.;
run;

2. Download the "want" dataset.

 

 

 

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
  • 3 replies
  • 7891 views
  • 0 likes
  • 3 in conversation