Date: Thu, 26 Jan 2012 21:11:22 -0600
Reply-To: Joe Matise <snoopy369@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Joe Matise <snoopy369@GMAIL.COM>
Subject: Re: how to refer to variable names in an array
In-Reply-To: <201201270005.q0QKDauf013083@waikiki.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1
You can refer to the current variable name with the VNAME() function, but
you can't create a new variable on the fly like that. You'd need to create
all of them ahead of time, more than likely; something like this:
%macro array_create_new(var);
&var._xyz
%mend;
proc sql;
select name into :arraylist separated by ' '
from dictionary.tables
where libname='WORK' and memname='A'
and substr(name,1,1) in ('A','B','C')
order by name;
select cats('%array_create_new(',name,')') into :arraynewlist separated
by ' '
from dictionary.tables
where libname='WORK' and memname='A'
and substr(name,1,1) in ('A','B','C')
order by name;
quit;
data foo;
set a;
array oldvars &arraylist;
array newvars &arraynewlist;
do _t = 1 to dim(oldvars);
if XXX then newvars[_t] = whatever;
end;
run;
Due to the simultaneous ordering, the variables will always correspond in
each array.
-Joe
On Thu, Jan 26, 2012 at 6:05 PM, Steven Zhang <zzhang@hsph.harvard.edu>wrote:
> Dear all,
>
> I have an array like this:
>
> data foo;
> set a;
> array test a: b: c:;
> run;
> based on some criteira, I need to make a new variable, which will be one of
> the array element plus a surfix, for example:
>
> do over test;
> if XXX then (???)_xyz = something;
> end;
>
> I am having trouble to refer to the variable name in the array, any help
> will be highly appreciated!
>
> Thanks.
>
|