As you noticed, you can do this. However, notice a couple of features about your program.
The value of &CONDITION does not include a semicolon ending the WHERE statement. The semicolon at the end of the %LET statement is needed to end the %LET statement. So the value of &CONDITION is:
where a>5
The program that refers to &CONDITION uses:
&condition;
That added semicolon following &CONDITION is what ends the WHERE statement.
If you wanted to include a semicolon as part of the value of &CONDITION, that is possible using:
%let condition = %str(where a>5; );
The %STR function treats the first semicolon as text, not as a symbolic character that ends the %LET statement.
You can answer your question by executing the code, reading the log and fixing errors that may be shown. If you need help fixing errors, post the log in code window see {i}-icon above the editing window.
As you noticed, you can do this. However, notice a couple of features about your program.
The value of &CONDITION does not include a semicolon ending the WHERE statement. The semicolon at the end of the %LET statement is needed to end the %LET statement. So the value of &CONDITION is:
where a>5
The program that refers to &CONDITION uses:
&condition;
That added semicolon following &CONDITION is what ends the WHERE statement.
If you wanted to include a semicolon as part of the value of &CONDITION, that is possible using:
%let condition = %str(where a>5; );
The %STR function treats the first semicolon as text, not as a symbolic character that ends the %LET statement.
I would NOT do it that way; if I have to do something similar, I do this:
%let condition=a>5;
data test;
set source;
where &condition.;
run;
That way it is clear which statement is executed, and only the condition itself comes from the macro variable. This makes code much more read- and maintainable.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.