DATA Step, Macro, Functions and more

Array - how to get variable name, not value of variable

Accepted Solution Solved
Reply
Contributor
Posts: 38
Accepted Solution

Array - how to get variable name, not value of variable

Hi all, I am trying to use an array with a loop to automate a process of marking rows for keeping.

I have a variable called "table" which contains output from a proc freq crosstab, so it contains variable names, e.g. "sex-1*county" "race-1*county".

Those same variables (sex-1 and race-1) are also variables in that same table, i.e.

---

table                      sex-1               race-1

sex1*county              .                      .
sex1*county             1                      .

race1*county             .                     1
race1*county             .                      .

---

data attempt;

set mytable;

array vlist sex-1 race-1;

do i = 1 to dim(vlist);

     if index(table,vlist{i}) then

          if vlist{i}=1, keepme=1;

end;

drop i;

run;

--

The problem with this is that when I search using INDEX, I believe SAS is using the value of the variable for that row, and not the variable name itself. Sorry for the long winded question, is there a way to return the array element as a text representation of the variable name, rather than the value of that variable in that row?

Thanks.


Accepted Solutions
Solution
‎12-18-2012 01:10 PM
Super User
Posts: 17,868

Re: Array - how to get variable name, not value of variable

use the vname function.

vname(vlist(i));

View solution in original post


All Replies
Solution
‎12-18-2012 01:10 PM
Super User
Posts: 17,868

Re: Array - how to get variable name, not value of variable

use the vname function.

vname(vlist(i));

Contributor
Posts: 38

Re: Array - how to get variable name, not value of variable

So simple - Thank you!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 212 views
  • 0 likes
  • 2 in conversation