BookmarkSubscribeRSS Feed
ambadi007
Quartz | Level 8

Dear Experts,

 

I am working on a project newly and that needs to be impute a date asper the requirement 

 

Stop date imputation:- Impute stop date as latest possible date (last day of the particular month if day is unknown or 31December if the day and month are unknwon)

I am having doubt how to get the last day of the month since every month has different last day and we need to consider the leap year also 

 

start date :-mpute stop date as earliest possible date (first day of the particular month if day is unknown or 1st january if the day and month are unknwon)

 

 

dates will be like below 

Stop date             Start date
2019-03               2018-03
2019                    2017
2018-03-25          2017-02-22

 

2 REPLIES 2
Kurt_Bremser
Super User

Expand the strings as needed, and use the intnx() function to determine the last day of a given month:

data want;
input (stop_string start_string) (:$10.);
if length(start_string) = 4 then start_string = cats(start_string,'-01');
if length(start_string) = 7 then start_string = cats(start_string,'-01');
start_date = input(start_string,yymmdd10.);
if length(stop_string) = 4 then stop_string = cats(stop_string,'-12');
if length(stop_string) = 7
then do;
  stop_string = cats(stop_string,'-01');
  stop_date = intnx('month',input(stop_string,yymmdd10.),0,'e');
end;
else stop_date = input(stop_string,yymmdd10.);
format start_date stop_date yymmddd10.;
drop start_string stop_string;
datalines;
2019-03               2018-03
2019                    2017
2018-03-25          2017-02-22
;
Reeza
Super User
INTNX() will allow you to get the last day of the month using the alignment parameter. Use the first as your day and then use the 'e' as the last parameter to increment to the end of the month.

last_month = intnx('month', today(), 0, 'e');

This would return March 30, 2020.

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 16. 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
  • 2 replies
  • 10763 views
  • 0 likes
  • 3 in conversation