Date: Wed, 27 May 2009 10:31:01 -0700
Reply-To: "Terjeson, Mark" <Mterjeson@RUSSELL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Terjeson, Mark" <Mterjeson@RUSSELL.COM>
Subject: Re: index(), vname() and a macro variable
In-Reply-To: A<8a57f3d1-2293-4cbe-bba1-a724485293c2@h28g2000yqd.googlegroups.com>
Content-Type: text/plain; charset="us-ascii"
Hi Adam,
The INDEX() matching is case sensitive.
The LOWCASE() or UPCASE() functions will
be handy here. Having the same macro variable
name containing the list will help as well.
Here is some working code, it has debugging
assignments and put statements left in so
you can see the underlying parts and pieces.
%let problem_vars=name sex weight hello;
data _null_;
set sashelp.class(obs=1);
array allvars _numeric_;
do i = 1 to dim(allvars);
s = vname(allvars{i});
t = "&problem_vars.";
x = index(upcase("&problem_vars."),
upcase(vname(allvars{i})));
put i= s= t= x= @;
if index(upcase("&problem_vars."),
upcase(vname(allvars{i}))) then
put 'variable name is present in list' @;
put;
end;
run;
Hope this is helpful.
Mark Terjeson
Investment Business Intelligence
Investment Management & Research
Russell Investments
253-439-2367
Russell
Global Leaders in Multi-Manager Investing
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Adam
Sent: Wednesday, May 27, 2009 10:03 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: index(), vname() and a macro variable
Hi All,
I'm trying to identify if a variable name is present in a macro
variable.
For instance, if a macro variable contains "list of possible variable
names" and one of the variables in a dataset is called "possible" then
I want to be able to tell.
I had hoped that something like this psuedo-code would work:
%let macro_var = list of possible variable names;
data _null_;
set indataset;
array allvars _numeric_;
do i = 1 to dim(allvars);
if index("&problem_vars.", vname(allvars{i})) then
/* variable name is present in list */
run;
but no matter what I do (including trying out %index, though I'm not
sure where the difference is), I can't get the if condition to work
(it just evaluates to 0 every time).
Any help much appreciated!
Thanks,
Adam