I find that, in macros, you need to be aware of if your date is in the numeric or in the literal format, which necessitates at least a pair of conversion macros.
%*-- two utilities --*;
%macro date2num(date, informat=anydtdte.);
%*-- strip quotations and postfix d from date literal if any. --*;
%*-- quotations are intentionally doubled to prevent unmatched error --*;
%let date=%sysfunc(prxchange(s/[''""]d?//i,-1,&date));
%sysfunc(inputn(&date,&informat))
%mend date2num;
%macro num2date(num, format=date10., literal=1);
%local n;
%let n = %sysfunc(putn(&num,&format));
%if &literal %then "&n"d; %else &n;
%mend num2date;
%*-- main work --*;
%macro today();
%num2date(%sysfunc(today()))
%mend today;
%macro LDoM(date=%today());
%sysfunc(intnx(mon,%date2num(&date),0,e))
%mend LDoM;
%macro IsLDoM(date=%today());
%sysevalf(&date = %LDoM(date=&date))
%mend IsLDoM;
%*-- check --*;
%macro test(date=);
%local not;
%let not = %qsysfunc(ifc(%IsLDoM(date=&date),,%str(not )));
&date is ¬.the last day of the month.
%mend test;
%put NOTE: %test(date="20may2011"d);
%put NOTE: %test(date="31may2011"d);
%*-- on log
NOTE: "20may2011"d is not the last day of the month.
NOTE: "31may2011"d is the last day of the month.
--*;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.