Robert, This is a fine example of a bad place to use the macro language.
In the vast majority of cases, a macro completes execution before the
generated data step begins. That is, the macro has done EVERYTHING it
is going to do before the data step processes the first observation.
You are asking for a macro to make decisions based on the data.
Unfortunately, the macro must make its decisions BEFORE the data is
Any solution to your problem will involve parsing the variable CONDITION
in each observation. You could have the macro write code to parse
CONDITION, but you have already written that code (according to your
post). It will be clearer and faster to use your existing parsing code
in a data step than to create a macro which can write the data step.
You refer to using the macro language to write "dynamic" SAS. The macro
language generates SAS which is "static" for any given set of parameter
values. There are exceptions to this, but none which will help you in
your current problem. You have already solved the problem better
without the macro language than it can be solved with the macro language
(this is not, in my old fogy opinion, a rare condition).
Tim Berryhill - Contract Programmer and General Wizard
Frequently at Pacific Gas & Electric Co., San Francisco
The correlation coefficient between their views and
my postings is slightly less than 0
----------------------[Reply - Original Message]----------------------
Sent by:Robert Agostinelli </G=Robert/S=Agostinelli/O=astra_usa_inc/OU
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
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
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
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
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
years old and the condition to pass requires them to be less than
Patient 3 would pass.
Does anyone know what the SAS macro code should be to perform this
Thanks for your help.