LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (August 2011, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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
In-Reply-To:  <AD4D009B201C104A87056D05DAEA2C1DF719E3@AZPH-SRV-MAIL09.cvty.com>
Content-Type: text/plain; charset="us-ascii"

Dear SAS-L-ers,

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. > example > > %let Gastro='Y'; > > Proc Sql and Data steps > > %if &Gastro=Y %then %do; > > Data Steps > > %end; > > 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;

%let Gastro=Y;

%macro bigmac;

%if &Gastro=Y %then %do;

proc print data=sashelp.class; run;

%end;

%mend bigmac;

%bigmac;

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" E-mail: MichaelRaithel@westat.com

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 http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=1&pc=58172

Author: The Complete Guide to SAS Indexes http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=1&pc=60409

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Hey man; what's shaking? - Michael A. Raithel +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


Back to: Top of message | Previous page | Main SAS-L page