Hello everyone,
From a date, I want to take the last day of the previous month. And after that, display the month and the year (of the previous month).
The problem is, my code is working for every month except January.
%let date="01JAN2017:00:00:00"dt;
%put ===> &date.;
data _null_;
last_day = day(intnx('month', datepart(&date.), -1, "end"));
CALL SYMPUT("last_day",PUT(last_day,DATE9.));
/*To display the month*/
p_month=MDY(month(datepart(&date.))-1, last_day, year(datepart(&date.))); /*Error here*/
CALL SYMPUT("p_month",PUT(p_month,FRADFMN.));
/*To display the year*/
p_year=MDY(month(datepart(&date.))-1, last_day, year(datepart(&date.))); /*Error here*/
CALL SYMPUT("p_year",PUT(p_year,YEAR4.));
run;
%put ===> &last_day.;
%put ===> &p_month.;
%put ===> &p_year.;
For January, I got the following error :
NOTE: Invalid argument for MDY function (0,31,2017) at line 31 column 9.
NOTE: Invalid argument for MDY function (0,31,2017) at line 34 column 8.
last_day=31 p_month=. p_year=. _ERROR_=1 _N_=1
NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to missing values.
How to tell SAS not to take month = 0 when it's January ?
Thank you in advance for your help !
Best regards,