Date: Wed, 15 Dec 2004 13:38:44 -0600
Reply-To: "Dunn, Toby" <Toby.Dunn@TEA.STATE.TX.US>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Dunn, Toby" <Toby.Dunn@TEA.STATE.TX.US>
Subject: Re: Explanation of Macro Code in Example
Content-Type: text/plain; charset="US-ASCII"
Micheal,
Proc sql;
select key into : keys separated by " "
from <dataset containing the keys>
where <person id> = "your personid of interest";
%let keys = f key = &keys;
%quit;
Now how you will use it is a different matter all together. If you plan
on using it say in a where clause you will want to add commas between
the different values, if it is a character variable instead of a numeric
you will want to add quotes and commas. Now what of the case where you
want to use it in a macro do-loop, well then you will need to have the
count of distinct values held in &keys. Of course it could also be the
case where you have to get the values from multiple sources, in that
case you might want to start thinking data step solution of a more
complex SQL solution. Or it might be the case that you don't even need
a macro variable at all.
It all depends on the details of the problem and the context to which
the macro variable will be used as to what method or how hard getting
what you want.
Toby Dunn
"It's OK to figure out murder mysteries, but you shouldn't need to
figure out code. You should be able to read it." -Steve C McConnell
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On
> Behalf Of Michael F. Murphy
> Sent: Wednesday, December 15, 2004 11:09 AM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Explanation of Macro Code in Example
>
>
> Toby,
>
> In this project a Kaiser staff person selects a patient ID to
> get a detailed list of costs for a year. These costs are
> widely dispursed throughout cost tables. For example, there
> is a table for prescription drug costs, a table for surgical
> costs, a table for physical therapy costs, and so on.
>
> The key variable contains a financial record number
> associated with a hospital stay.
>
> When the user selects a patient ID, for a period of a year, a
> patient may have more than one hospital stay, hence more than
> one "key".
>
> The system used is an old system called s1032. The SAS
> procedure is called PROS S1032S. This will be converted to a
> relational database system in the future, but this program
> still uses s1032 tables.
>
> The PROC S1032S code has this statement:
> exec = "f key = &key";
>
> The desired result in the example is:
> exec = "f key = 11111 22222 33333 44444";
>
> Since this patient had four hospital stays, there are four "keys".
>
> The macro &key goes against the table for prescription drug
> costs, the table for surgical costs, the table for physical
> therapy costs, and so on. That's why we used the macro &key
> in the program. The program worked until we found that a
> patient can have more than one "key" value, since a patient
> can have more than one hospital stay in a year.
>
> Mike
>
>
>
>
>
> "Dunn, Toby" <Toby.Dunn@tea.state.tx.us>
> 12/15/2004 08:46 AM
>
>
> To: Michael F Murphy/OR/KAIPERM@Kaiperm,
> <SAS-L@LISTSERV.UGA.EDU>
> cc:
> Subject: RE: Need Help on a Macro
>
>
> Mike,
>
> Some sample code or even a little more info. would be helpful
> here as it is unclear exactly how you intend for the value of
> this macro variable to be used in the sas code and how you
> intend the value(s) to get into the macro variable is
> unclear. My first inclination is to use a %macro, but after
> that it all dependes on your answers to the above mentioned questions.
>
>
> Toby Dunn
>
> "It's OK to figure out murder mysteries, but you shouldn't
> need to figure out code. You should be able to read it."
> -Steve C McConnell
>
>
>
> > -----Original Message-----
> > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On
> Behalf Of
> > Michael F. Murphy
> > Sent: Wednesday, December 15, 2004 10:37 AM
> > To: SAS-L@LISTSERV.UGA.EDU
> > Subject: Need Help on a Macro
> >
> >
> > Dear SAS-L ers,
> >
> > Once again I need your help.
> >
> > In this project, a user runs a program to select data on a person.
> >
> > In one of the selected data sets, there are "key" values. A
> person can
> > have none, one, or several key amounts.
> >
> > These key amounts need to be put into a macro variable
> separated by a
> > space for further processing.
> >
> > Let us assume that a person selected has the following four key
> > values: 11111 22222 33333 44444
> >
> > These need to be put into the following macro variable:
> >
> > %let key = 11111 22222 33333 44444;
> >
> > so that when &key is called the following is put into the
> > code: 11111 22222 33333 44444
> >
> > Any suggestions?
> >
> > Thanks.
> >
> > Mike
> >
>
|