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

Hello folks!

A small question concerning the automation of macro's-

SO let's say I have %a & %b that I want to run under certain circumstances-

Lets say that if the day of the month is between 1 and 7 I want %a to run otherwise I want %b to run;

Thank you all again.

Lawrence

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

One way would be with a third macro.  Something like the following should work:

%macro driver;

  %if %sysfunc(day(%sysfunc(today()))) le 7 %then %do;

    %a

  %end;

  %else %do;

    %b

  %end;

%mend driver;

%driver

View solution in original post

7 REPLIES 7
art297
Opal | Level 21

One way would be with a third macro.  Something like the following should work:

%macro driver;

  %if %sysfunc(day(%sysfunc(today()))) le 7 %then %do;

    %a

  %end;

  %else %do;

    %b

  %end;

%mend driver;

%driver

_LB
Fluorite | Level 6 _LB
Fluorite | Level 6

Thanks Art.

That helps. I was close but was missing an element or two.

_LB
Fluorite | Level 6 _LB
Fluorite | Level 6

Art,

Question-

If i want to simply end the program if it does not fall on a specific day, how does that go?

Thanks.

Lawrence

art297
Opal | Level 21

I think that would depend on precisely what you want to happen next.  If you just want to stop a currently running data step you could always just route the code to a stop statement.  e.g.,

http://support.sas.com/documentation/cdl/en/imlug/59656/HTML/default/viewer.htm#programstatements_se...

_LB
Fluorite | Level 6 _LB
Fluorite | Level 6

Hi Art-

Thanks for the link, however, It is part of a larger macro so that I just want to "kill" the program if it doesn't fall on a specific day, plus actually I have a few programs bundled as well so I don't want to recode everything again.  Is this feasible?

Thanks again.

Lawrence

%macro driver;

  %if %sysfunc(day(%sysfunc(today()))) le 7 %then %do;

    %a

  %end;

  %else %do;

    "KILL PROGRAM" ?

  %end;

%mend driver;

%driver

art297
Opal | Level 21

You have numerous options depending on just what you want to terminate, e.g., abend, abort and systask.  Take a look at the following thread: http://www.mathkb.com/Uwe/Forum.aspx/sas/41557/Re-Kill-the-sas-program-if-it-runs-too-long

_LB
Fluorite | Level 6 _LB
Fluorite | Level 6

Ah yes-the good ole %abort function. Thanks & Have a great weekend!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1900 views
  • 0 likes
  • 2 in conversation