DATA Step, Macro, Functions and more

%IF.%THEN.%ELSE Required Operator not found

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

%IF.%THEN.%ELSE Required Operator not found

I am trying to write a macro to execute some code on the first day of the month or the second if Sunday was the first.

v9.2

 

   %MACRO NEWMTH;                                                
    %IF  (DAY(TODAY()) = '1' AND WEEKDAY(TODAY()) NE '1')        

    %THEN %DO ;   

. . .

  RUN;             
  %END ;           
 %MEND NEWMTH;     
 %NEWMTH ;         

 

MLOGIC(NEWMTH):  Beginning execution.                                          
ERROR: Required operator not found in expression: (DAY(TODAY()) = '1' AND WEEKDAY(TODAY()) NE '1')  
ERROR: The macro NEWMTH will stop executing.                                   
MLOGIC(NEWMTH):  Ending execution.                                         

 

What did I code wrong?    I never attempted this type of macro before.    Can this be done?    

 

 


Accepted Solutions
Solution
‎02-19-2016 02:06 PM
Super User
Posts: 17,785

Re: %IF.%THEN.%ELSE Required Operator not found

Yes, you can create your macro variables in advance. I recommend doing so via a data _null_ step as it's easier to debug until you're an expert with macro's.

View solution in original post


All Replies
Super User
Posts: 17,785

Re: %IF.%THEN.%ELSE Required Operator not found

You can't use SAS functions in macro code without using %sysfunc.

 

So you're TODAY and WEEKDAY() functions are not resolving.

Wrap them in %sysfunc(), each function needs it's own. 

 

 

 

This implementation does make sense as it's an explicit way to tell SAS how to differentiate from text vs actual code.

 

Occasional Contributor
Posts: 9

Re: %IF.%THEN.%ELSE Required Operator not found

Could I make macro variables for date and day before the macro so it would look like %if &date = 1 and &day ne 1 ... ?
Solution
‎02-19-2016 02:06 PM
Super User
Posts: 17,785

Re: %IF.%THEN.%ELSE Required Operator not found

Yes, you can create your macro variables in advance. I recommend doing so via a data _null_ step as it's easier to debug until you're an expert with macro's.

Occasional Contributor
Posts: 9

Re: %IF.%THEN.%ELSE Required Operator not found

Yes, That was my intention. Thank you.
Occasional Contributor
Posts: 9

Re: %IF.%THEN.%ELSE Required Operator not found

SOLUTION CODE:

 

 DATA _NULL_ ;                                         
 %LET TDAY = %SYSFUNC(DAY(%SYSFUNC(TODAY())))   ;      
 %LET WDAY = %SYSFUNC(WEEKDAY(%SYSFUNC(TODAY())))   ;  
                                                       

 %MACRO NEWMTH;                          
  %IF  (&TDAY = 1 AND &WDAY NE 1)                  
    %THEN %DO ;                          

. . .

  RUN;             
  %END ;           
 %MEND NEWMTH;     
 %NEWMTH ;     

 

MLOGIC(NEWMTH):  Beginning execution.                            
SYMBOLGEN:  Macro variable TDAY resolves to 19                   
SYMBOLGEN:  Macro variable WDAY resolves to 6                     
MLOGIC(NEWMTH):  %IF condition (&TDAY = 1 AND &WDAY NE 1)    is FALSE                                              
MLOGIC(NEWMTH):  Ending execution.                               

Super User
Posts: 10,487

Re: %IF.%THEN.%ELSE Required Operator not found

Your DATA _NULL_ statement is not needed.

Since you are using %LET to define the variables there is no datastep operation involved.

 

I believe what @Reeza was thinking of when mentioning data _null_ was something like this:

 

data _null_;

   call symputx('TDAY',day(today()));

   call symputx('WDAY', weekday(today()));

run;

Occasional Contributor
Posts: 5

Re: %IF.%THEN.%ELSE Required Operator not found

[ Edited ]

hi all.

first, i know that it is a pretty old topic, but, i am new at sas and having a similar issue, but in my case my varyables are already setled, and still having issues

 

 %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.

Super User
Posts: 17,785

Re: %IF.%THEN.%ELSE Required Operator not found

@GabrielGajardo Please start your own thread instead. 

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 376 views
  • 4 likes
  • 4 in conversation