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

Here is what I have 

 

data have;
input year month;
infile datalines missover;
datalines;
2020 1
2020 2
2020 3
;

 

Keen to want below:

31Jan2020

29Feb2020

31Mar2020

 

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
data want;
set have;
date = mdy(month, 1, year);
date_month_end = intnx('month', date, 0, 'e');
format date: date9.;
run;


@ywon111 wrote:

Here is what I have 

 

data have;
input year month;
infile datalines missover;
datalines;
2020 1
2020 2
2020 3
;

 

Keen to want below:

31Jan2020

29Feb2020

31Mar2020

 

Thanks in advance


 

View solution in original post

3 REPLIES 3
Reeza
Super User
data want;
set have;
date = mdy(month, 1, year);
date_month_end = intnx('month', date, 0, 'e');
format date: date9.;
run;


@ywon111 wrote:

Here is what I have 

 

data have;
input year month;
infile datalines missover;
datalines;
2020 1
2020 2
2020 3
;

 

Keen to want below:

31Jan2020

29Feb2020

31Mar2020

 

Thanks in advance


 

japelin
Rhodochrosite | Level 12

how about this 

data want;
  set have;
  dmy=intnx ('month',mdy(month,1,year),0,'E');
  format dmy date9.;
run;
ballardw
Super User

One way:

data have;
input year month;
infile datalines missover;
dateval = intnx('month',mdy(month,1,year),0,'E');
format dateval date9.;
datalines;
2020 1
2020 2
2020 3
;

The MDY function uses month, day and year values to create a date, in this case using 1 for day as every month has a day 1.  The INTNX function then adjusts that date to the end of that current month, 'month' being the interval, 0 being the current month to adjust the date value and 'E' to set the end of the interval.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 2407 views
  • 3 likes
  • 4 in conversation