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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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