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

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)

 

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

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;
Log :
75 %put &SOM;
01FEB2019

 

View solution in original post

2 REPLIES 2
ed_sas_member
Meteorite | Level 14

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;
Log :
75 %put &SOM;
01FEB2019

 

Kurt_Bremser
Super User

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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