0
votes

Reaching out to understand what's happening...

I'm storing some dates in some macro variables -

data _null_;
call symput('month_tag',put(intnx('month',today(),-0),monname3.));
call symput('year',put(intnx('year',today(),0),year.));
run;
%put &month_tag &year;

We can then use this sample data set -

data sample;
input test_a test_b test_c;
cards;
173 181 172
;
run;

The data set represents a final step in the process after many summaries have been done. We want to display these summaries with the time period. If I pass the macro-variables holding the dates to the newly created invoice variable, we don't quite get what we want -

data out;
set sample;
invoice = &month_tag._&year;
run;

enter image description here

If you can run this output, you will see that for some reason SAS is creating the variable invoice as it should, but instead of using the macro-variable value, its taking that value and producing another variable with the value as the new variable's name.

I got around it with -

data out2;
set sample;
invoice = "&month_tag._&year";
run;

My instinct tells me it has something to do with the way I am using/printing the &month_tag._&year within the invoice variable, but if anyone could clear this up for me I would appreciate it.

1
&month_tag._&year is resolved as Feb_2018, without " ", It is regarded as variable in sample, which apparently doesn't exist in sample, so invoice get missing values; with " ", it is regarded as value ( Feb_2018). - Shenglin Chen

1 Answers

1
votes

The macro variable's value just replaces the reference and SAS then interprets the resulting text as the code to run. So you are just describing the difference between these two statements.

invoice = Feb_2018;
invoice = "Feb_2018";

In the first one the right hand side is a variable reference. In the second it is a string literal.