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;

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 2939 views
  • 2 likes
  • 5 in conversation