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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
singhsahab
Lapis Lazuli | Level 10

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;

 

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.  

Astounding
PROC Star

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.

singhsahab
Lapis Lazuli | Level 10

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;

 

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
  • 4 replies
  • 2693 views
  • 2 likes
  • 5 in conversation