BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ucdcrush
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
2 REPLIES 2
Reeza
Super User

use the vname function.

vname(vlist(i));

ucdcrush
Obsidian | Level 7

So simple - Thank you!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 13604 views
  • 2 likes
  • 2 in conversation