jpsfer
jpsfer

Reputation: 594

SAS pass column name through variable

I need to pass a column name through a variable.

%let dsn=a1234;
data temp;
   set &a1234;
   if age>=20;
run;

Where 'a1234' is the column name (present in the file) that I want to use; and not the string a1234.

The reason I want to do this is to have all the parameters defined at the top of the script which makes the code more clean (in this case).

Thanks in advance for any feedback.

Upvotes: 0

Views: 3032

Answers (2)

BellevueBob
BellevueBob

Reputation: 9618

Although your question says a1234 is a column, this answer treats it as a data set name, as used in your code example.

You were very close; you created a macro variable named DSN with a value of a1234, but you tried to reference a macro variable named A1234. In other words, try this:

%let DSN=a1234;
data temp;
   set &DSN;
   if age>=20;
run;

Capitalized for emphasis.

Upvotes: 3

Jay Corbett
Jay Corbett

Reputation: 28441

Are you asking about doing this?

%let dsn=a1234;
%Let column=Age;
data temp;
 set &a1234;
 if &column>=20;
run;

Upvotes: 1

Related Questions