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.
--*;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.