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 2025: Call for Content

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!

Submit your idea!

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