Dear,
I need create a an ENDDATE variable from date variable values.
If complete date is provided then the date will be the end date.
If Month provided then last day of the month will be the ENDDATE value.
If year only provided then last day of the year will be the ENDDATE value.
Please help
id date
1 2015-01-06
2 2015-11
3 2015
4 2015-02
Output needed:
ENDDATE
06JAN2015
30NOV2015
31DEC2015
28FEB2015
Generate a valid SAS date and then use SAS function intnx()
enddate = intnx("MONTH", date, 0, "END");
/* or */
enddate = intnx('YEAR", date, 0, "END");
Here's one way for character values.
data want;
set have;
/* assumes your "date" is CHARACTER*/
Enddate = input(date,anydtdte32.);
/* missing is because year provides insufficient information to anydtdte*/
/* so assign last day of dec as day and month*/
if missing(enddate) then enddate = mdy(12,31,input(date,best4.));
/* anydtdte when day of month is missing assigns day to be 1, this is
one way to advance to last day of current month */
if length(date)=7 then enddate=intnx('month',enddate,1)-1;
format enddate date9.;
run;
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!
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.