Date: Wed, 27 May 2009 14:10:23 -0400
Reply-To: Jack Clark <jclark@HILLTOP.UMBC.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jack Clark <jclark@HILLTOP.UMBC.EDU>
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"
Adam,
Randy's recent post on this topic brings up another point to consider.
In the code your provided, you were only checking for NUMERIC variables
in the INDATASET to match to your list. The solutions Mark, Joe and I
posted kept this assumption. Randy's code is checking all variables
(CHARACTER and NUMERIC). Which do you want?
If you want to check all variables, and still use an ARRAY solution, you
may need separate _numeric_ and _character_ arrays. Or look at Randy's
post for a non-array approach.
Jack Clark
Senior Research Analyst
phone: 410-455-6256
fax: 410-455-6850
jclark@hilltop.umbc.edu
University of Maryland, Baltimore County
Sondheim Hall, 3rd Floor
1000 Hilltop Circle
Baltimore, MD 21250
Confidentiality Notice: This e-mail may contain information that is legally privileged and that is intended only for the use of the addressee(s) named above. If you are not the intended recipient, you are hereby notified that any disclosure, copying of this e-mail, distribution, or action taken in reliance on the contents of this e-mail and/or documents attributed to this e-mail is strictly prohibited. If you have received this information in error, please notify the sender immediately by phone and delete this entire e-mail. Thank you.-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Adam
Sent: Wednesday, May 27, 2009 1:03 PM
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