Simple Macro [3-5]
Referencing a Macro Variable
In this section, we will look at how to reference a macro variable properly.
As seen in previous sections, we can reference a macro variable by putting an ampersand in front of the variable.
%let var1 = 123;
%put The value of macro variable var1 is &var1;
In this example, &VAR1 is the reference to the macro variable VAR1.
It displays the value of the macro variable which is 123.
Referencing a Macro Variable Within Quotations
When referencing a macro variable within quotations, you must use double quotes.
Single quotes do not work.
Let's look at an example.
%let name = Alfred;
name_sin = '&name';
name_dou = "&name";
In this example, we defined the macro variable NAME as Alfred.
We then define two variables that are intended to contain the name Alfred.
Please note that we used single quotes for the NAME-SIN variable and double quotes for the NAME-DOU variable:
The macro variable reference (&name) was not resolved when placed within single quotes:
The SASHelp.fish data set contains a list of 159 fishes and their weight, length and height.
Write a SAS program to compute the mean and standard deviation of the weight of the fish for Whitefish.
The value Whitefish should be dynamically assigned using a macro variable.
Need some help?