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

Hi, i currently have a script to convert from yymmn6. (201801) to mmmYYYY (jan2018).

However, if it is march, i want it to be converted to mac, instead of mar as default.

 

my script:

%let period=201808;

data _null_;
	monthyr=input("&period",yymmn6.);
	call symputx('month',lowcase(cats(put(monthyr,worddate3.),year(monthyr))));
run;
%put &=month;

%put &month;

%if %substr(&month,1,3) eq 'mar' %then %do;
	%sysfunc(tranwrd(&month,'mar','mac'))
%end;

 

I had no luck at all. What actually wrong here?

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Use Base SAS, previously mentioned several times.

%let period=201808;

data _null_;
  monthyr=input("&period",yymmn6.);
  result=lowcase(cats(put(monthyr,worddate3.),year(monthyr)));
  result=tranwrd(result,"mar","mac");
  call symputx('month',result);
run;

%put &month.;

However, I cannot stress this enough, avoid using such structures in filenames/code.  If you need to have date on something use ISO dates - they are sortable, and processable without language issues (i.e. in your case here), do not have upper/lower case issues, and can be partial without issue.  This is what mostly everyone else uses, its an international standard for a reason.

 

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Use Base SAS, previously mentioned several times.

%let period=201808;

data _null_;
  monthyr=input("&period",yymmn6.);
  result=lowcase(cats(put(monthyr,worddate3.),year(monthyr)));
  result=tranwrd(result,"mar","mac");
  call symputx('month',result);
run;

%put &month.;

However, I cannot stress this enough, avoid using such structures in filenames/code.  If you need to have date on something use ISO dates - they are sortable, and processable without language issues (i.e. in your case here), do not have upper/lower case issues, and can be partial without issue.  This is what mostly everyone else uses, its an international standard for a reason.

 

imdickson
Quartz | Level 8

Thanks @RW9 . I would definitely adapt to your suggestion. Very much appreciated.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 825 views
  • 0 likes
  • 2 in conversation