Date: Wed, 21 Aug 1996 07:54:52 -0700
Reply-To: Karsten Self <kmself@IX.NETCOM.COM>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Karsten Self <kmself@IX.NETCOM.COM>
Subject: Re: Using a variable's values to create SAS source code
If I'm reading you right, no macro required, though possibly a different
data structure. Suppose you 'condition' to 'HiAge' and 'LoAge'. You can
use these values in comparison operators. Four cases to consider:
hi= missing, lo= missing: don't perform comparison
hi= non-missing, lo= missing: test age < hi
hi= missing, lo= non-missing: test age > lo
hi= non-missing, lo= non-missing: test lo < age < hi
You indicate that other types of comparison are possible, eg: sex. Add a
field and perform similar logic.
There are two methods for generating code based on data values. One uses
macros and the call symput statement, eg:
mname= 'fred'; x= 1; y= 2;
call symput( mname, put( x, 8.0 ));
call symput( 'sue', put( y, 8.0 ));
...creates two macrovariables 'fred' (value of 'mname') and 'sue' with
values '1' and '2' respectively. For your application, the macrovariable
overhead is probably too great -- macrovariables use memory.
An alternate method is the call execute statement. This resolves its
arguments to generate code which is executed following the close of the data
step. I use this technique, though in your case it will not generate code
to be applied in the current data step. Again, you would be producing a
program with a block of statements corresponding to each observation in your
At 02:36 PM 8/20/96 -0500, you wrote:
> Hi folks,
> I have a SAS dataset ( with 1000's of observations ) that has 4
> Patient Age Sex Condition
> ------- --- --- ------------------------------------------
> 1 21 M If age > 12 and age < 26
> 2 63 F If age < 18
> 3 45 M If age > 18 and sex = M
> The condition variable is different for each observation. I have
> already written the SAS code that parses the condition into three
> variables: a low age range, a high age range, and the sex condition.
> In reality, the condition also contains criteria for race and other
> parameters as well.
> However, I am looking for a cleaner solution than having to parse the
> text. I would like to be able to use the value of the condition
> variable as part of the SAS program that evaluates the observation as
> pass/fail. To do this, I know that macros are required to build
> dynamic SAS code.
> Therefore, I want to create a 5th variable that flags whether or not
> the current obs. meets it's own condition.
> For example, patient 1 would pass it's own condition, and the flag
> would be set to 'pass'. Patient 2 would fail since the patient is 63
> years old and the condition to pass requires them to be less than 18.
> Patient 3 would pass.
> Does anyone know what the SAS macro code should be to perform this
> Thanks for your help.
Karsten Self / firstname.lastname@example.org
What part of gestalt don't you understand?