No quoting
Macro variables need/must not be quoted when used as argument to a function within
%sysfunc
. When the same macro variable is used in a
data step, it needs to be quoted:
%let var=foo bar baz;
/* &var is used in macro context: it needs not be
quoted: */
%put length of var is %sysfunc(length(&var));
data _null_;
/* &var is used in a data step: it must be
must be quoted: */
len = length("&var");
put "length of var is " len;
run;
putn
The following example uses
%sysfunc
to call
putn in order to format a variable with a specific
format.
putn
is needed because
put is not available in the macro environment.
%macro tq84_yyyymm;
%do yyyy=2015 %to 2017;
%do m = 1 %to 12;
%let mm=%sysfunc(putn(&m, z2.));
%put &yyyy&mm;
%end; %end;
%mend tq84_yyyymm;