Date: Thu, 27 Feb 2003 03:34:07 +0000
Reply-To: John Whittington <John.W@MEDISCIENCE.CO.UK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: John Whittington <John.W@MEDISCIENCE.CO.UK>
Subject: Re: Help on Macro
In-Reply-To: <E18oEL0-0003jv-00@coumxnn02.netbenefit.co.uk>
Content-Type: text/plain; charset="us-ascii"; format=flowed
At 18:53 26/02/03 -0800, Kit Leung wrote:
>I would like to know how do we add an if statement before any procedure
>steps?
>For example, if id = 123 then do the proc sort.... Can we use %if %then
>statement?
Not if 'id' is an ordinary (DATA step /dataset) variable - because that
does not exist outside of a DATA or PROC step. However, you can do it by
using macrovariables, in all sorts of ways. One way is to use a 'flag'
macrovariable to change the RUN statement of a proc into 'RUN CANCEL' when
you do NOT want the PROC to execute, something like:
data one ;
<your code in here>
if id = 123 then call symput('flag',' ') ;
else call symput ('flag','cancel') ;
run ;
proc whatever ;
<your code>
run &flag ;
You'd obviously have to be careful with how you set the value of the
macrovariable - since, for example, with the above code, the value of
'flag' would change with each iteration of the DATA step, hence it would be
the value of id in the very last iteration of the DATA step which would
determine whether or not the PROC was executed.
Kind Regards
John
----------------------------------------------------------------
Dr John Whittington, Voice: +44 (0) 1296 730225
Mediscience Services Fax: +44 (0) 1296 738893
Twyford Manor, Twyford, E-mail: John.W@mediscience.co.uk
Buckingham MK18 4EL, UK mediscience@compuserve.com
----------------------------------------------------------------
|