BookmarkSubscribeRSS Feed
kevinharshads1
Calcite | Level 5

I'm pulling data from a database to load into another database. The file spec I've been given says the date I need to provide be in yyyy/mm/dd hh:mm format.

The date field I'm pulling is in SQL Server and it's a datetime field, but from the SAS library side of things it shows as "Number". How can I have it export to my Excel export as a date, and in the yyyy/mm/dd hh:mm format? (e.g. 2019/04/01 00:00)

 

 

2 REPLIES 2
yabwon
Amethyst | Level 16

Hi @kevinharshads1 ,

 

Since SAS keeps dates/ datetimes as a number of days/seconds since January 1st 1960 I would start with adding proper format to the variable you have and then do the export to Excel, e.g.

proc format;
picture myDate (default=16)
          other='%Y/%0m/%0d %0H:%0M' (datatype=datetime);
run;

data want;
  set have;
  format myVariableName myDate.;
run;

proc export data = want ...

All the best

Bart

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Reeza
Super User
SAS stores dates and times as numbers, what matters on the SAS side is the format, which controls how it's displayed to the user. You need to apply the correct format to have it applied. However, I will say that when pulling directly from a Server datetimes usually come across perfectly fine so does it actually look incorrect to you when viewing the data. SAS only has two types of data, character/numeric.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 782 views
  • 0 likes
  • 3 in conversation