hi all.
Due to @Reeza, recomendation im opening this thread.
I am new at sas and having some issues with %IF %ELSE conditions, I am trying to write a macro to execute some code on the when the last date, on a data set, is from "today - 1" but whe i run the macro it keep giving the error "Required operator not found in expression"
/* +++++++++ Variables*/
rsubmit;
proc sql;
select max(offer_Date) into :valDateSales
from qwer ;
quit;
proc sql;
select max(offer_Date) into :valDateOffers
from asdf;
quit;
%let maxDateSales= %sysfunc(substrn(&valDateSales.,1,9));
%let maxDateOffers= %sysfunc(substrn(&valDateOffers.,1,9));
endrsubmit;
/* +++++++++ MACRO*/
%macro Continuity(MaxDateSales, MaxDateOffers);
%Let yesterday = %eval(%sysfunc(today())-1);
%if ("&MaxDateSales."d eq "&yesterday."d)%then %do;
%if ("&MaxDateOffers."d eq "&yesterday."d)) %then %do;
%export_to_Drive(ds=workunx.X, outf_name=ASDF..csv)
%export_to_Drive(ds=workunx.Y, outf_name=qwer.csv)
%export_to_ftp(dsn=workunx.x,outfile_name=asdf..csv));
%export_to_ftp(dsn=workunx.Y ,outfile_name=qwer..csv));
%successMailing();
%put "succes statement";
%end;
%else %do;
%failMailing();
%end
%else %do;
%failMailing();
%put "fail statement";
%end;
%mend;
/*++++++LOG
693 %Continuity(MaxDateSales=&MaxDateSales., MaxDateOffers=&MaxDateOffers.);
MLOGIC(CONTINUITY): Beginning execution.
SYMBOLGEN: Macro variable MAXDATESALES resolves to 20806
SYMBOLGEN: Macro variable MAXDATEOFFERS resolves to 20806
MLOGIC(CONTINUITY): Parameter MAXDATESALES has value 20806
MLOGIC(CONTINUITY): Parameter MAXDATEOFFERS has value 20806
MLOGIC(CONTINUITY): %LET (variable name is YESTERDAY)
SYMBOLGEN: Macro variable MAXDATESALES resolves to 20806
SYMBOLGEN: Macro variable YESTERDAY resolves to 20806
MLOGIC(CONTINUITY): %IF condition ("&MaxDateSales."d eq "&yesterday."d) is TRUE
SYMBOLGEN: Macro variable MAXDATEOFFERS resolves to 20806
SYMBOLGEN: Macro variable YESTERDAY resolves to 20806
ERROR: Required operator not found in expression: ("&MaxDateOffers."d eq "&yesterday."d))
ERROR: The macro CONTINUITY will stop executing.
MLOGIC(CONTINUITY): Ending execution.
NOTE: Remote submit to A complete.
well as i have said, i am new at SAS so please, any help will be appreciated.
It can't hurt to remove the d (as Reeza suggested). But the likely cause of the problem is that you have an extra right-hand parenthesis on that same line of code.
(Also note a couple of instances of an extra right-hand parenthesis on two of the later lines that call the macro.)
Your macro is nested and you're calling several different macros. I think the error is in one of those macros, not the one shown.
Is this your code or are you running someone else's and trying to debug?
PS please try and format the code, I know the forum does change it sometimes, but the current layout is difficult to read.
1.- it is my code, but is an extention for an older code of some one else.
2.- i have tried to comment all the macros that this code is calling, but the error stay there.
3.- i have tried to format de posted code, but the forum change it a lot =(
thaks for the quick reply
Try fixing this issue:
SYMBOLGEN: Macro variable MAXDATESALES resolves to 20806
SYMBOLGEN: Macro variable MAXDATEOFFERS resolves to 20806
Your code:
%if ("&MaxDateOffers."d eq "&yesterday."d)) %then %do;
Replacing the values generates invalid SAS code:
%if ("20806"d eq "20806"d)) %then %do;
Your dates are not formatted correctly. So either format them as Date9 or remove the D from the comparison.
It should look like:
%if ("18Dec2016"d eq "18Dec2016"d)) %then %do;
As %IF compares character strings ther is no need -
neither to use "&var"d nor change into "ddmmmyy"d
but just to use
%if &MAXDATESALES = &MAXDATEOFFERS
It can't hurt to remove the d (as Reeza suggested). But the likely cause of the problem is that you have an extra right-hand parenthesis on that same line of code.
(Also note a couple of instances of an extra right-hand parenthesis on two of the later lines that call the macro.)
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.