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.

 

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 9330 views
  • 0 likes
  • 3 in conversation