DATA Step, Macro, Functions and more

automating macros w/ if & then statements

Accepted Solution Solved
Reply
Regular Contributor
Regular Contributor
Posts: 170
Accepted Solution

automating macros w/ if & then statements

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


Accepted Solutions
Solution
‎10-03-2011 01:54 PM
PROC Star
Posts: 7,363

automating macros w/ if & then statements

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


All Replies
Solution
‎10-03-2011 01:54 PM
PROC Star
Posts: 7,363

automating macros w/ if & then statements

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

Regular Contributor
Regular Contributor
Posts: 170

automating macros w/ if & then statements

Thanks Art.

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

Regular Contributor
Regular Contributor
Posts: 170

automating macros w/ if & then statements

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

PROC Star
Posts: 7,363

automating macros w/ if & then statements

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

Regular Contributor
Regular Contributor
Posts: 170

automating macros w/ if & then statements

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

PROC Star
Posts: 7,363

automating macros w/ if & then statements

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

Regular Contributor
Regular Contributor
Posts: 170

automating macros w/ if & then statements

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

☑ This topic is SOLVED.

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

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