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