Date: Thu, 20 Dec 2007 07:33:50 -0800
Reply-To: karma <dorjetarap@GOOGLEMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: karma <dorjetarap@GOOGLEMAIL.COM>
Organization: http://groups.google.com
Subject: Re: assigning column variable to macro variable
Content-Type: text/plain; charset=ISO-8859-1
Thanks all for you replies, I remembered symput as soon as I had
posted this. The problem I now have is that I need to execute a macro
call and assign it to a column value for each record. The following
code only calculates this once and duplicates the first calculated
values into the entire column. For eg. column trt1 has the value "1
(6%) " for the entire column.
Cheers.
%macro calcPercent(numer,denom);
/* macro to calculate percent and return correctly formatted value
*/
%if &numer ^=. %then %do;
%let pct=%sysfunc(round((&numer/&denom)*100,1));
%if &pct<1 %then
%let pct=&numer (<1%);
%else %if 1=&pct or &pct<10 %then
%let pct=&numer (%substr(&pct,1,1)%);
%else %if 10=&pct or &pct<100 %then
%let pct=&numer (%substr(&pct,1,2)%);
%else
%let pct=&numer (%substr(&pct,1,3)%);
%end;
%else %let pct=0;
"&pct";
%mend calcPercent;
%macro test;
data ae1Any;
set ae5;
%do i=1 %to &trtGrps;
call symput("freq&i.",freqpc&i);
trt&i=%calcPercent(numer=&&freq&i,denom=&&bign&i);
%end;
call execute (trt1=%calcPercent(numer=&freq1,denom=&bign1));
call symput('freq999',freqpc999);
trt999=%calcPercent(numer=&freq999,denom=&bignTot);
run;
%mend test;
%test;
On Dec 20, 3:23 pm, karma <dorjeta...@googlemail.com> wrote:
> On Dec 20, 2:02 pm, Chris.Bro...@ONS.GOV.UK (Chris Brooks) wrote:
>
>
>
>
>
> > Try this macro
>
> > %%macro vname;
> > %let dsid=%sysfunc(open(sashelp.class,i));
>
> > %do i=1 %to %sysfunc(attrn(&dsid,nvars));
> > %global var&i;
> > %let var&i=%sysfunc(varname(&dsid,&i));
> > %end;
> > %let rc=%sysfunc(close(&dsid));
> > %mend;
> > %vname;
>
> > Chris
>
> > Chris Brooks
> > SAS Technical Lead
> > Office for National Statistics
> > United Kingdom
>
> > On Thu, 20 Dec 2007 05:35:58 -0800, karma <dorjeta...@GOOGLEMAIL.COM>
> > wrote:
>
> > >Hi,
>
> > >I want to know if there is a way to make a column variable a global
> > >variable.
>
> > >The following doesn't work
>
> > >data _null_;
> > > set test;
> > > %global var1;
> > > %let var1=variableOne;
> > >run;
>
> > >This makes var1 resolve to the text variableOne, rather than the value
> > >in column variableOne. Any suggestions?
>
> > >Thanks- Hide quoted text -
>
> > - Show quoted text -
>
> Hi Chris,
>
> Can you please explain what this macro does? It looks like it creates
> global variables for all column values?
>
> Cheers- Hide quoted text -
>
> - Show quoted text -
|