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?
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.
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.
Thanks @RW9 . I would definitely adapt to your suggestion. Very much appreciated.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.