Conditional coding

Accepted Solution Solved
Reply
Contributor AD
Contributor
Posts: 31
Accepted Solution

Conditional coding

I'd like to set up a macro variable that controls what SAS code gets run.  For example, I have two different SAS programs, let's call them Program 1 and Program 2.  These programs are pretty short, so I could copy and paste them into the same program.

At the top of my program, I would like to define a macro variable called "Option" that takes on a value of 1 or 2.  If option = 1, then I want SAS to run the code associated with Program 1.  If option = 2, then I want SAS to run the code associated with Program 2.  How would I go about setting that up?

I know to set up the macro variable, the first line would be:

%let option = 1; 

But then what would I need to write to get SAS to only run one section of code while ignoring another section?

Thanks,

Andy


Accepted Solutions
Solution
‎11-02-2012 04:09 PM
PROC Star
Posts: 7,467

Re: Conditional coding

You can wrap them in a set of conditionally executed call execute statements.  The example at:

http://support.sas.com/kb/24/730.html

isn't quite the same as you are describing, but could easily be modified to check the value of a macro variable.  Similarly, the example wraps the code in SAS macros, while that isn't actually necessary.

View solution in original post


All Replies
Solution
‎11-02-2012 04:09 PM
PROC Star
Posts: 7,467

Re: Conditional coding

You can wrap them in a set of conditionally executed call execute statements.  The example at:

http://support.sas.com/kb/24/730.html

isn't quite the same as you are describing, but could easily be modified to check the value of a macro variable.  Similarly, the example wraps the code in SAS macros, while that isn't actually necessary.

Contributor AD
Contributor
Posts: 31

Re: Conditional coding

Perfect, that's exactly what I was looking for.  Thanks!

🔒 This topic is solved and locked.

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

Discussion stats
  • 2 replies
  • 155 views
  • 0 likes
  • 2 in conversation