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.
--*;
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.