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

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