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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 542 views
  • 1 like
  • 3 in conversation