Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

Are you asking about doing this?

%let dsn=a1234;
%Let column=Age;
data temp;
 set &a1234;
 if &column>=20;
run;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top