Date: Wed, 24 Aug 2011 14:13:59 +0000
Reply-To: Michael Raithel <michaelraithel@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Michael Raithel <michaelraithel@WESTAT.COM>
Subject: Re: Conditional Macro
Content-Type: text/plain; charset="us-ascii"
Nicholas Adams posted the following:
> I have a program that has a series of data steps and proc sqls. I have
> one section of it that I want to run if a condition is true. I set a
> macro variable called gastro at the begining of the code to be either Y
> of N. I cant seen to get the syntax right of running the section of
> code conditionally.
> %let Gastro='Y';
> Proc Sql and Data steps
> %if &Gastro=Y %then %do;
> Data Steps
> Rest of Proc Sql and Data Steps
Nick, you are going to kick yourself when you see how easy the solution is! Simply drop the quotes around the letter Y and it will work. So, the %LET statement should read:
%let Gastro = Y;
Here is a fun example to play with:
options symbolgen mprint mlogic;
%if &Gastro=Y %then %do;
proc print data=sashelp.class;
Run it first as-is, then change the Y to N and run it. Capiche?
Now, don't kick yourself too hard, we all do this at one time or another:-)
Nick, best of luck in all your SAS endeavors!
I hope that this suggestion proves helpful now, and in the future!
Of course, all of these opinions and insights are my own, and do not reflect those of my organization or my associates. All SAS code and/or methodologies specified in this posting are for illustrative purposes only and no warranty is stated or implied as to their accuracy or applicability. People deciding to use information in this posting do so at their own risk.
Michael A. Raithel
"The man who wrote the book on performance"
SAS Press Author Page: http://support.sas.com/publishing/authors/raithel.html
Author: Tuning SAS Applications in the MVS Environment
Author: Tuning SAS Applications in the OS/390 and z/OS Environments, Second Edition
Author: The Complete Guide to SAS Indexes
Hey man; what's shaking? - Michael A. Raithel