Suppose you want to
write a PROC PRINT step that you can reuse without any modification
to print information about each course. You can do this by using an
indirect reference in the TITLE statement.
data _null_;
set certadv.courses;
call symputx(course_code,(course_title));
run;
%let crsid=C002;
proc print data=certadv.schedule noobs label;
where course_code="&crsid";
var location begin_date teacher;
title1 "Schedule for ???";
run;
In the example above,
the macro variable C002 (as created by the SYMPUTX routine) has a
value of Structured Query Language
.
Therefore, the TITLE statement should reference a macro variable that
resolves to Structured Query Language
.
Remember that you want this reference to be flexible enough to apply
to any of the macro variables that the SYMPUTX routine creates, such
as C003 or C004, by changing only the %LET statement.
To obtain the value
that you want, you must indirectly reference the macro variable C002
through a reference to the macro variable Crsid. If the value of the
macro variable Crsid is C002
, the following
process might seem to be correct:
-
Resolve the macro variable
Crsid to the value C002
.
-
Attach an ampersand
(&
) to the front of the resolved value
in order to create a new reference (&C002).
-
Resolve the resulting
macro variable reference to the value Structured Query
Language
.
This sequence seems
to imply that you should use the reference &&crsid to convert
the value of the macro variable Crsid to the corresponding course
description. However, the indirect reference rules indicate that this
is not the correct solution.
Here is the correct
solution:
title1 "Schedule for &&&crsid";