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

The following macro returns date in monYY format. The output is having the month name in all caps e.g. DEC19 while the desired output is Dec19. What changes should be made to the macro to get the output in the required format. 

 

Thanks in advance !

%macro iter();
data _null_;

%do i = 1 %to 12;
%global monthy&i.;
call symput("monthy&i.",put(intnx('month',&dt.,(-&i.)+1,'e'),monyy5.)));
%end;
run; %mend; %iter();
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
You could just nest it with PROPCASE?

%macro iter();
data _null_;

%do i = 1 %to 12;
%global monthy&i.;
call symput("monthy&i.", propcase(put(intnx('month',&dt.,(-&i.)+1,'e'),monyy5.))));
%end;

run;

%mend;
%iter();

View solution in original post

3 REPLIES 3
Reeza
Super User
You could just nest it with PROPCASE?

%macro iter();
data _null_;

%do i = 1 %to 12;
%global monthy&i.;
call symput("monthy&i.", propcase(put(intnx('month',&dt.,(-&i.)+1,'e'),monyy5.))));
%end;

run;

%mend;
%iter();
somepathak
Calcite | Level 5

Thanks, it worked. Just that the code you shared had too many brackets, but removing them got me the required result. Appreciate the help, thanks again !

Tom
Super User Tom
Super User

Why did you code a %DO loop in a data step?

data _null_;
  do i=1 to 12;
    call symputx(cats('monthy',1)
                ,propcase( put( intnx('month',&dt.,1-i,'e') ,monyy5.) )
                ,'g');
  end;
run;

Also why are you using only 2 digits for the year?  Use MONYY7 to get full four digits of the year.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 3 replies
  • 1019 views
  • 1 like
  • 3 in conversation