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