0
votes

I have two numeric variables, date1 and date2, which are both currently set to 20170502.

In my macro, I want to send an email if the two variables are equal. This is my code:

%let date1 = input(put(intnx('day', today(),-3),yymmddn8.),8.); 
%macro EMAIL;
filename INSRNC email;
data _null_;  
%if &date1. = &date2. %then %do; 
file INSRNC to="email@address"
subject= "test";
put "email message";
%end; 
run; 
%mend;
%EMAIL;

I am getting the error message: "Required operator not found in expression"

Am I using the wrong operator?

Thanks

2

2 Answers

1
votes

If these are defined macro variables, then this should work as you posted it. I would recommend making a modification; you should pass date1 and date2 as parameters, even if they are just passed as is, due to the principle of encapsulation. But what you posted would work, just based on global macro variables.

%let date1=20140101;
%let date2=20140101;
%macro EMAIL(date1=, date2=);
filename INSRNC email;
data _null_;  
%if &date1. = &date2. %then %do; 
  *file INSRNC to="email@address"
subject= "test";
  put "email message";
%end; 
run; 
%mend;

%EMAIL(date1=&date1., date2=&date2.);

If you're getting required operator not found in expression then your macro variables are not correctly defined and may have a character in them that is making this fail to read properly. Use OPTIONS MPRINT SYMBOLGEN; to see why.

1
votes

@Joe gave a perfect explanation on how to define macros. Passing the macros as parameters makes it far easy. However, looking at your comment on how date1 is getting resolved, please see the below

date1 = %sysfunc(input(put(intnx('day', today(),-3),yymmddn8.),8.));

Kindly read through the importance of %Sysfunc in resolving macros to have a better understanding.