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 1996, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 20 Aug 1996 14:47:41 PDT
Reply-To:   TWB2%Rates%FAR@GO50.COMP.PGE.COM
Sender:   "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:   TWB2%Rates%FAR@GO50.COMP.PGE.COM
Subject:   Re: Using a variable's values to create SAS source code

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 available.

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 TWB2@PGE.COM 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 Hi folks,

I have a SAS dataset ( with 1000's of observations ) that has 4 variables:

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 . . . etc.

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 task?

Thanks for your help.

=====================================================================


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