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

Hi Techies,

I came across a requirement to concatenate month and year and from that concat I have to get the previous month end.
I tried with PUT(mdy(t1.MONTH_NUMBER, 1, t1.YEAR_WORKED),MMDDYY10.) and I am getting like 03/01/2016 if the month is MARCH and theYEAR is 2016, in this case.

here is the data I am having
Data having :
YEAR_WORKED                    MONTH_NAME                                DATE_WANTED
2016                                        MARCH                                             28FEB2016
2016                                        APRIL                                                31MAR2016
2016                                        NOVEMBER                                      31OCT2016
2017                                         FEBRUARY                                       31JAN2017
2017                                        MARCH                                              28FEB2017
2018                                         APRIL                                                31MAR2018
2018                                         MAY                                                  30APR2018
2018                                         SEPTEMBER                                    31AUG2018


Really appreciate if some one Could please help me .

Thanks,
Vickys

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Do like this

 

data have;
input year_worked month_name :$15.;
datalines;
2016 MARCH
2016 APRIL
2016 NOVEMBER
2017 FEBRUARY
2017 MARCH
2018 APRIL
2018 MAY
2018 SEPTEMBER
;

data want;
   set have;
   date_wanted=input(cats(substr(MONTH_NAME, 1, 3), YEAR_WORKED), monyy7.)-1;
   format date_wanted date9.;
run;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Do like this

 

data have;
input year_worked month_name :$15.;
datalines;
2016 MARCH
2016 APRIL
2016 NOVEMBER
2017 FEBRUARY
2017 MARCH
2018 APRIL
2018 MAY
2018 SEPTEMBER
;

data want;
   set have;
   date_wanted=input(cats(substr(MONTH_NAME, 1, 3), YEAR_WORKED), monyy7.)-1;
   format date_wanted date9.;
run;
vickys
Obsidian | Level 7

Thanks Draycut.

really appreciate your help

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