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

Hi,

 

I want the following sas date format: YYYY-MM-DD

Can someone help to achieve this?

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Two display formats exist that display SAS date values (counts of days, where 1960-01-01 is day zero) in this manner: YYMMDDD10. or E8601DA10.

If you have to start with something that looks like a date, but is not yet a SAS date value, please tell us the type (numeric or character) and the current format attached to the variable.

View solution in original post

7 REPLIES 7
Kurt_Bremser
Super User

Two display formats exist that display SAS date values (counts of days, where 1960-01-01 is day zero) in this manner: YYMMDDD10. or E8601DA10.

If you have to start with something that looks like a date, but is not yet a SAS date value, please tell us the type (numeric or character) and the current format attached to the variable.

psrajput
Obsidian | Level 7
Thanks, I could not find it anywhere on the internet. And that's how bigquery takes a date variable.
Kurt_Bremser
Super User

First, bookmark this link:

SAS® 9.4 and SAS® Viya® 3.4 Programming Documentation 

From there, open Data Step Programming to find the chapters dealing with Formats/Informats, Functions/Call Routines, and other DATA step related information. The Dictionary of Formats offers to find Formats by Category, so you get a place where to start looking for date formats.

LeonidBatkhan
Lapis Lazuli | Level 10

Hi KurtBremser, I think you mistyped the format YYMMDD10. as YYMMDDD10. (extra D). Isn't it?

Kurt_Bremser
Super User

@LeonidBatkhan wrote:

Hi KurtBremser, I think you mistyped the format YYMMDD10. as YYMMDDD10. (extra D). Isn't it?


No. The extra "D" instructs SAS to use the dash as delimiter (default is a forward slash). See here.

LeonidBatkhan
Lapis Lazuli | Level 10

Hi KurtBremser,

 

Interesting. I run

 

data _null_;
   d='30jul2020'd;
   put d= yymmdd10.;
run;

(without extra d) and it gives me the date with hyphens:

 

d=2020-07-30

Apparently in the YYMMDDxw. Format default (when x is not present) is hyphen.

 

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