BookmarkSubscribeRSS Feed
dht115
Calcite | Level 5

Hello, 

 

I need date format to YYYY_DD.

So far I was able to get the date format in YYYY-DD by using following code: 

/*yymmd7. format - YYYY-DD*/
%let today2 = %sysfunc(today(),yymmd7.);
%put &today2.;

Result: 2022-01

 

Need: 

Result: 2022_01

3 REPLIES 3
PaigeMiller
Diamond | Level 26

You would have to create a custom format using the PICTURE command in PROC FORMAT.

 

Example: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/p1717ykol58oijn13lw9rs30lhn0.htm

--
Paige Miller
PeterClemmensen
Tourmaline | Level 20

See if you can use this as a template

 

proc format; 
  picture dtfmt (default = 30)
    other = '%Y_%0m' (datatype=date)
  ;
run;

%let dt = %sysfunc(today(), dtfmt.);
%put &dt.;
BrunoMueller
SAS Super FREQ

I assume by YYYY_DD you mean year_month

 

The code below uses the NLDATE function to build the string your are after. When you have nested DATA Step functions, each function needs its own %SYSFUNC. The %NRSTR macro function avoids warning messages.

/*yymmd7. format - YYYY-DD*/
%let today2 = %sysfunc(nldate(%sysfunc(today()),%nrstr(%Y_%m)));
%put &today2.;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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