Hello
I have a program that user define macro varaible
%let CurMon=1907;
I need to create another macro variable(called SOM) that its value is calculated automatically from the value of &CurMon.
The value should be start of month and written in format date9.
So in this case I should get value '01JUL2019'd
other examples:
%let CurMon=1908;
SOM should get value '01AUG2018'd
%let CurMon=1902;
SOM should get value '01FEB2018'd
What is the way to do it please using %SYSFUNC function please?(or other way)
Hi @Ronein
I believe in your example, 1908 should refer to 01AUG2019 and not 2018 ?
You can try this code:
%let CurMon=1902;
%let SOM = %sysfunc(putn(%sysfunc(MDY(%sysfunc(substr(&CurMon,3,2)),1,%sysfunc(substr(&CurMon,1,2)))),date9.));
%put &SOM;
Hi @Ronein
I believe in your example, 1908 should refer to 01AUG2019 and not 2018 ?
You can try this code:
%let CurMon=1902;
%let SOM = %sysfunc(putn(%sysfunc(MDY(%sysfunc(substr(&CurMon,3,2)),1,%sysfunc(substr(&CurMon,1,2)))),date9.));
%put &SOM;
Since you obviously want to use it in code, not for display, formatting is not necessary, so you do
%let som=%sysfunc(inputn(20&curmon.01,yymmdd8.));
and get the raw value of the date literal.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.