Lesson 9, Part 5: Combining Macro Variables with Text¶
Macro variable reference after text is not a problem.¶
In [39]:
*Ex6_Join_macro_var_text.sas (Part 1);
options nosymbolgen;
%LET dsn = month;
title;
data work.&dsn;
var1=1;
run;
%put work.&dsn;
Out[39]:
The SAS System
work.month
E3969440A681A2408885998500000040
Trailing text after the macro variable reference is a problem. In this situation, you must put a dot after the macro variable reference.¶
In [16]:
*Ex6_Join_macro_var_text.sas (Part 2);
options symbolgen;
%LET dsn = month;
data work.&dsn.1;
var1=1;
run;
%put &dsn.1;
Out[16]:
The SAS System
SYMBOLGEN: Macro variable DSN resolves to month
SYMBOLGEN: Macro variable DSN resolves to month
month1
E3969440A681A2408885998500000016
Adjacent macro variable references are never a problem.¶
In [46]:
*Ex6_Join_macro_var_text.sas (Part 3);
*Join two macro variables;
%LET dsn = month;
%LET xdsn=1;
data work.&dsn&xdsn;
var1=1;
run;
%put work.&dsn&xdsn;
Out[46]:
The SAS System
work.month1
E3969440A681A2408885998500000046
Two dots are required because the single dot in the two-level name is considered as text after the first macro variable reference.¶
In [17]:
*Ex6_Join_macro_var_text.sas (Part 4);
options nonotes;
%LET Path=C:\Users\pmuhuri\Documents;
%LET Libref=New;
libname &Libref "&Path";
data &Libref..&dsn;
var1=1;
run;
Out[17]:
The SAS System
SYMBOLGEN: Macro variable LIBREF resolves to New
SYMBOLGEN: Macro variable PATH resolves to C:\Users\pmuhuri\Documents
SYMBOLGEN: Macro variable LIBREF resolves to New
SYMBOLGEN: Macro variable DSN resolves to month
E3969440A681A2408885998500000017