date problem exporting to excel

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

date problem exporting to excel

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!


Accepted Solutions
Solution
‎10-14-2015 11:39 AM
Respected Advisor
Posts: 3,837

Re: date problem exporting to excel

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


All Replies
Super Contributor
Posts: 305

Re: date problem exporting to excel

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.

 

 

Occasional Contributor
Posts: 18

Re: date problem exporting to excel

Hello,
Thank you for your recommendation. I finally finished it Smiley Happy
Solution
‎10-14-2015 11:39 AM
Respected Advisor
Posts: 3,837

Re: date problem exporting to excel

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.

 

 

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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