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
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
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.;
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.;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.