BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MandM
Fluorite | Level 6

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?    

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

8 REPLIES 8
Reeza
Super User

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.

 

MandM
Fluorite | Level 6
Could I make macro variables for date and day before the macro so it would look like %if &date = 1 and &day ne 1 ... ?
Reeza
Super User

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.

MandM
Fluorite | Level 6
Yes, That was my intention. Thank you.
MandM
Fluorite | Level 6

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.                               

ballardw
Super User

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;

GabrielGajardo
Fluorite | Level 6

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.

Reeza
Super User

@GabrielGajardo Please start your own thread instead. 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 8 replies
  • 8098 views
  • 4 likes
  • 4 in conversation