| Date: | Thu, 26 Jan 2006 00:46:21 +0000 |
| Reply-To: | toby dunn <tobydunn@HOTMAIL.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | toby dunn <tobydunn@HOTMAIL.COM> |
| Subject: | Re: global/local macro variables within macro |
|
| In-Reply-To: | <"0328C43D7A44B001*/c=gb/admd=gold400/prmd=dss/o=departmentofsocialsecurity/ou=asd/s=Nachbar/g=Dirk/"@MHS> |
| Content-Type: | text/plain; format=flowed |
|---|
Dirk,
Sorry its taken me so long to get back to you, but work was crazy. What I
had in mind is that you already had a data set that contains the model name
and the parameters. Now all you need is a way to retrieve these values at
will. To do this without going through a data step you need a macro
solution. Since there are no prepackaged macros from SAS its a do it
yourself thang...
Ian showed me how to do this the other day and I think I will pass it along.
%macro GetParms ( data = , Model= , Parm = ) ;
%local rc dsnid vn value ;
%let dsnid = %sysfunc( open ( &data (keep = &Parm Model where =
(upcase(Model) = "%upcase(&model)")), i ) ) ;
%if &dsnid ^= 0 %then %do ;
%let rc = %sysfunc(fetch(&dsnid,noset)) ;
%if &rc = 0 %then %do ;
%let vn = %sysfunc(varnum(&dsnid,&Parm)) ;
%if &vn ^= 0 %then %do ;
%let Value = %sysfunc(getvarn(&dsnid,&vn)) ;
%end ;
%else
%put %sysfunc(sysmsg()) ; /* mistake in data specs */
%end ;
%else
%put %sysfunc(sysmsg()) ; /* open but could not fetch */
%let rc = %sysfunc(close(&dsnid)) ;
%end ;
%else
%put %sysfunc(sysmsg()) ; /* could not open */
&Value
%mend GetParms ;
/********************************/
/** Data with Model Parms **/
/********************************/
data one ;
infile cards ;
input Model $ Parm1 Parm2 Parm3 ;
cards ;
Model1 11 21 31
Model2 12 22 32
Model3 13 23 33
;
run ;
/*****************************/
/** Retrieve Parms **/
/*****************************/
%put %sysfunc( Compbl(
Model1 = %GetParms( data = One , Model = Model1 , Parm = Parm1 )
+ %GetParms( data = One , Model = Model1 , Parm = Parm2 )
+ %GetParms( data = One , Model = Model1 , Parm = Parm3 ) ) ) ;
%put %sysfunc( Compbl(
Model2 = %GetParms( data = One , Model = Model2 , Parm = Parm1 )
+ %GetParms( data = One , Model = Model2 , Parm = Parm2 )
+ %GetParms( data = One , Model = Model2 , Parm = Parm3 ) ) ) ;
%put %sysfunc( Compbl(
Model3 = %GetParms( data = One , Model = Model3 , Parm = Parm1 )
+ %GetParms( data = One , Model = Model3 , Parm = Parm2 )
+ %GetParms( data = One , Model = Model3 , Parm = Parm3 ) ) ) ;
Toby Dunn
From: Dirk Nachbar <Dirk.Nachbar@DWP.GSI.GOV.UK>
Reply-To: Dirk Nachbar <Dirk.Nachbar@DWP.GSI.GOV.UK>
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: global/local macro variables within macro
Date: Wed, 25 Jan 2006 16:16:11 Z
Toby
I know that it looks messy. I partly understand what you mean but do not
know
how to implement it. I guess you mean something like this:
%macro model(outest,name);
data &outest;
set &outest;
if _depvar_="&name" then /*read all the parameters into what
exactly??*/;
run;
%mend;
help would be appreciated.
Dirk Nachbar
Assistant Economist
Pensim2
Department for Work and Pensions
Level 4, The Adelphi
1-11 John Adam St
WC2N 6HT London
020 796 28531
tobydunn@hotmail.com
25/01/2006 16:04
To
Dirk Nachbar/London/Asd@ASD, SAS-L@LISTSERV.UGA.EDU@internet
cc
Subject
Re: global/local macro variables within macro
Dirk,
So basically you have the values in a data set and you just need to be able
to retrieve these values when you need them. Mixing, matching, and
interleaving datastep code with macro the way you have it one is ugly to
look at no matter who writes it and how well they write it, secondly it will
lead you down the road to headache land in teh future that no amount of
asprin will cure.
A better solution is simply to write a macro that you supply the model name
too and the variable you want the value of and have the macro retrieve it
from the data set and output it to where you want it at. No messy data step
and macro code confusion and no making a zillion possible global macro vars,
which means that the house keeping will be a cinch.
Toby Dunn
From: Dirk Nachbar <Dirk.Nachbar@DWP.GSI.GOV.UK>
Reply-To: Dirk Nachbar <Dirk.Nachbar@DWP.GSI.GOV.UK>
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: global/local macro variables within macro
Date: Wed, 25 Jan 2006 15:07:35 Z
Toby
the bigger picture is as follows: I have an outest table with nine models
corresponding to the nine macro variables. I want to call-symput the
parameters
from the table in order to do forecasts later on. Since I want to write it
in a
general way I do not want to write out all the call-symput's manually. as
you
can see the models have common regressors (age etc.,)
Dirk Nachbar
Assistant Economist
Pensim2
Department for Work and Pensions
Level 4, The Adelphi
1-11 John Adam St
WC2N 6HT London
020 796 28531
tobydunn@HOTMAIL.COM
25/01/2006 14:57
To
SAS-L@LISTSERV.UGA.EDU@internet
cc
Subject
Re: global/local macro variables within macro
Dirk,
To solve your immediate question you will want to can the use of two ampers
and go with three as that will allow for the resolved value of 'var' to be
resolved as a macro value. Remember in macro land rules && resolves to &
after the first pass thus in your case if &var resolves to Pay, then &&var
will resolve to Pay also, you need &&&var to get Macro var Pay to resolve to
its values so the scan will have more than one element to work on.
Now the whole need to have three ampers and the global macro variables
smells of bad macro design. However, to pull a page from David Cassell 'I
dont yet know your larger picture' I would be just guessing as Ian puts.
If you write back and give us your larger problem and if you give us a
sample data set and the desired outcome I bet one of us could find a
simplier way to get to where you want to get to.
Toby Dunn
From: Dirk Nachbar <Dirk.Nachbar@DWP.GSI.GOV.UK>
Reply-To: Dirk Nachbar <Dirk.Nachbar@DWP.GSI.GOV.UK>
To: SAS-L@LISTSERV.UGA.EDU
Subject: global/local macro variables within macro
Date: Wed, 25 Jan 2006 14:40:19 Z
Dear all
I want to simplify call-symput statements within a macro. therefore I have a
macro variable &vars which has all nine variables in it. in my macro %symput
there seems to be a confusion between &var and &&var, but i do not know how
to
resolve that. &count should be the number of variables within the nine
individual variables.
Dirk
%let pay=intercept lpay age agemale male;
%let cl1wks=intercept lcl1wks age agemale male cl1wksmale;
%let stdweeks=intercept lstdweeks age stdweeksmale;
%let stdef=intercept lstdef age agemale male stdefmale;
%let coef=intercept lcoef age agemale male coefmale;
%let oowwks=intercept loowwks age male oowwksmale;
%let cl2wks =intercept lcl2wks age agemale male;
%let tpaynpc=intercept ltpaynpc age agemale male;
%let coweeks=intercept lcoweeks age agemale male;
%macro symput(vars=);
data home.tscs;
set home.tscs;
%do i= 1 %to 9;
%let var=%scan(&vars,&i);
if _depvar_="&var" then do;
%let count=%eval(
%length(&&var)-%length(%sysfunc(compress(&&var)))+1 );
%put &count;
%do j=1 %to &count ;
call symput("&&var&j",%scan(&&var,&j));
%end;
end;
%end;
run;
%mend;
%symput(vars=pay cl1wks stdweeks stdef coef oowwks cl2wks tpaynpc coweeks);
Dirk Nachbar
Assistant Economist
Pensim2
Department for Work and Pensions
Level 4, The Adelphi
1-11 John Adam St
WC2N 6HT London
020 796 28531
**********************************************************************
This document is strictly confidential and is intended only for use by the
addressee.
If you are not the intended recipient, any disclosure, copying, distribution
or other
action taken in reliance of the information contained in this e-mail is
strictly prohibited.
Any views expressed by the sender of this message are not necessarily those
of the Department
for Work and Pensions.
If you have received this transmission in error, please use the reply
function to tell us
and then permanently delete what you have received.
Please note: Incoming and outgoing e-mail messages are routinely monitored
for compliance
with our policy on the use of electronic communications.
**********************************************************************
The original of this email was scanned for viruses by the Government Secure
Intranet (GSi) virus scanning service supplied exclusively by Cable &
Wireless in partnership with MessageLabs.
On leaving the GSi this email was certified virus-free
PLEASE NOTE: THE ABOVE MESSAGE WAS RECEIVED FROM THE INTERNET.
On entering the GSi, this email was scanned for viruses by the Government
Secure Intranet (GSi) virus scanning service supplied exclusively by Cable &
Wireless in partnership with MessageLabs.
Please see http://www.gsi.gov.uk/main/notices/information/gsi-003-2002.pdf
for
further details.
In case of problems, please call your organisational IT helpdesk
The original of this email was scanned for viruses by the Government Secure
Intranet (GSi) virus scanning service supplied exclusively by Cable &
Wireless in partnership with MessageLabs.
On leaving the GSi this email was certified virus-free
PLEASE NOTE: THE ABOVE MESSAGE WAS RECEIVED FROM THE INTERNET.
On entering the GSi, this email was scanned for viruses by the Government
Secure Intranet (GSi) virus scanning service supplied exclusively by Cable &
Wireless in partnership with MessageLabs.
Please see http://www.gsi.gov.uk/main/notices/information/gsi-003-2002.pdf
for
further details.
In case of problems, please call your organisational IT helpdesk
The original of this email was scanned for viruses by the Government Secure
Intranet (GSi) virus scanning service supplied exclusively by Cable &
Wireless in partnership with MessageLabs.
On leaving the GSi this email was certified virus-free
|