turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Table cell indicating which column's value to use ...

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

01-24-2013 12:22 AM

Hi,

I am looking for a straightforward / easy way to do the following:

Say I have the table:

data INPUT_DATASET;

input a $1. b c;

datalines;

b 10 20

c 30 40

b 50 60

c 70 80

;

run;

The first variable (i.e. a) is the name of the column/variables of which I want to use the value in an equation. Say my equation is 10*X, where X is either the value of b or c, depending on what column a says it should be. (I don't want to use IF statements, for I work from the assumption that I don't know the variables that column a can refer to. I need it more dynamic than that.)

What I have tried, which obviously did not work but would illustrate what I want, is the following:

data TEST_OUTPUT;

set INPUT_DATASET;

call execute('%let current_var = ' || a );

TEST=10*¤t_var;

run;

The warning is:

WARNING: Apparent symbolic reference CURRENT_VAR not resolved

So, my question is: is there an easy straightforward way to do what I want to do, or should I work around it (such as first determining the unknown variables (b and c in this case) and then using a macro with a loop over the determined list of variables)?

Thanks,

Pieter

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

01-24-2013 02:42 AM

A colleague of mine suggested using the VNAME function, so I do have a solution now:

data TEST;

set INPUT_DATASET;

array numeric_vars{*} _NUMERIC_;

do i = 1 to dim(numeric_vars);

if vname(numeric_vars{i}) = a then do;

TEMP_VALUE = numeric_vars{i};

leave;

end;

end;

TEST = TEMP_VALUE*10;

drop i TEMP_VALUE;

run;

Is there perhaps an even more straight forward way than looping through the variables?