Search notes:

SAS programming - macro function: %sysfunc

%sysfunc is a macro function that can execute most data step functions.
/* %sysfunc (and %qsysfunc) can execute most SAS functions */

%let text=foo bar baz;
%let sub_4_3=%sysfunc(substr(&text, 5, 3));
%put &sub_4_3;

%put %sysfunc(date(), worddate.);
Github repository about-SAS, path: /macro-processor/functions/sysfunc/basic.sas

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;
Github repository about-SAS, path: /macro-processor/functions/sysfunc/no-quoting.sas

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;
Github repository about-SAS, path: /macro-processor/functions/sysfunc/putn.sas

See also

macro functions

Index