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.

有帮助吗?

解决方案

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.

其他提示

Are you asking about doing this?

%let dsn=a1234;
%Let column=Age;
data temp;
 set &a1234;
 if &column>=20;
run;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top