BookmarkSubscribeRSS Feed
Filipvdr
Pyrite | Level 9
data _null_;
format LastDayOfMonth date.;
LastDayOfMonth = intnx('month',today(),1)-1;
call symput ('LastDayOfMonth',LastDayOfMonth);
run;
%put &lastdayofmonth; (THIS IS A NUMBER)

%macro updateL3;
%if today() eq &lastdayofmonth %then %do;
...
%end;
%mend;
%updateL3;

ERROR: Required operator not found in expression: today() eq %eval(&lastdayofmonth)
ERROR: The macro UPDATEL3 will stop executing.
4 REPLIES 4
ChendhilKumar
Calcite | Level 5
Answer: Use %sysfunc(today()) when using today() in macro.


%macro update;

data _null_;
format LastDayOfMonth date.;
LastDayOfMonth = intnx('month',today(),1)-1;
call symput ('LastDayOfMonth',LastDayOfMonth);
run;
%put DEBUG::(&SYSMACRONAME)::Last day of month is &lastdayofmonth;
%put DEBUG::(&SYSMACRONAME)::Today is %sysfunc(today());

%if %sysfunc(today()) eq &lastdayofmonth %then %do;
%put DEBUG::(&SYSMACRONAME)::updated;
%end;
%else %do;
%put DEBUG::(&SYSMACRONAME)::Not updated;
%end;

%mend update;

/* ---- Call update ---- */
%update;

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Log output:
-----------------
DEBUG::(UPDATE)::Last day of month is 18778
DEBUG::(UPDATE)::Today is 18767
DEBUG::(UPDATE)::Not updated
Filipvdr
Pyrite | Level 9
ok thanks! have to review my sas macro i guess 🙂
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You can use CALL EXECUTE to conditionally invoke a SAS code-piece/program/macro from within your DATA step, thus avoiding the "date-related' conditional macro logic.

Scott Barry
SBBWorks, Inc.
chang_y_chung_hotmail_com
Obsidian | Level 7

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

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 2367 views
  • 0 likes
  • 4 in conversation