SAS: Macro Variable
- 1 minOverview
1. %LET statement
Syntax:
%LET macro-variable-name = text-or-text-value;
2. Using the INTO in PROC SQL
Creating a single value:
PROC SQL;
SELECT var-1, var-2
INTO :macro-var-1, :macro-var-2
FROM table;
QUIT;
Note: only the first record is assigned to the macro variable, when there are multiple records.
Creating lists of values:
Using SEPERATED BY
:
PROC SQL;
SELECT var-1, var-2
INTO :macro-var-1 SEPERATED BY ',',
:macro-var-2 SEPERATED BY ' '
FROM table;
QUIT;
Using THROUGH
:
PROC SQL;
SELECT var-1, var-2
INTO :macro-var-1-x THROUGH :macro-var-1-y,
:macro-var-2-x THROUGH :macro-var-2-y
FROM table;
QUIT;
From ¯o-var-1-x
to macro-var-1-y
variables, each of them stores each record of var-1
from the $x^{th}$ row to the $y^{th}$ row. And the same for ¯o-var-2-x
to macro-var-2-y
.
No upper bound:
PROC SQL; SELECT var-1, var-2 INTO :macro-var-1-, :macro-var-2- FROM table; QUIT;
3. Using the CALL SYMPUTX routine
Syntax:
DATA _NULL_;
CALL SYMPUT('macro_var', value);
RUN;
%PUT ¯o_var;
Reference
- Five Ways to Create Macro Variables: A Short Introduction to the Macro Language
- proc sql - select into
- SYMPUT and SYMGET: Getting DATA Step Variables and Macro Variables to Share