Previously I used to extract month and date field as follows.
NEW_RENEWAL_DAY_MONTH_YEAR=mdy(NEW_RENEWAL_MONTH,NEW_RENEWAL_DAY,RENEWAL_YEAR);
format DATE5.;
Then I convert the date field to character as follows.
NEW_RENEWAL_DAY_MONTH_YEAR_char=put(NEW_RENEWAL_DAY_MONTH_YEAR,date5.);
So that the output will be like 21NOV or 31DEC ... in character. Now the requirement is to get the values like 11-21 or 12-31. Since we do not have any formats like mmdd5. or similar format, I'm not certain how to achieve this. Please guide me.
data HAVE;
input date DATE9.;
FORMAT DATE MMDDYYD10.;
datalines;
31DEC2018
21NOV2018
;
run;
DATA WANT;
SET HAVE;
NEW_D=SUBSTR(PUT(DATE,MMDDYYD10.),1,5);
RUN;
Use a yymmddd10. format and extract the last 5 characters with substr(.....,6).
I would ask why you want only day-month in either format. Unless you have specific (very) data, then that date part is going to be pretty useless. Why not just put a proper date on there and be done with it, yymmdd10 gives a nice sortable (in directory views and such like), and ISO dates are pretty standard now.
A trick for brevity:
length newvar $ 5;
newvar = put(new_renewal_day_month_year, mmddyyd10.);
There is only room to store the first five characters, so that's going to be the result.
data HAVE;
input date DATE9.;
FORMAT DATE MMDDYYD10.;
datalines;
31DEC2018
21NOV2018
;
run;
DATA WANT;
SET HAVE;
NEW_D=SUBSTR(PUT(DATE,MMDDYYD10.),1,5);
RUN;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.