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.

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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