1
votes

I have written a simple macro and applied it in a simple SAS data step to illustrate an issue I am having with viewing output.

Macro:

%macro test_func(var=);
%put &var;
%mend;

Data step:

data test_data_step;
value = 0;
%test_func(var = value);
run;

My issue is that the output I see is just the string value rather than the value held in the variable whose name is equal to that string.

I believe I have a vague understanding as to why SAS is doing this, but I don't know how to get it to give the desired value (namely 0 in this case). So how would I be able to achieve that functionality?

Thanks!

1

1 Answers

3
votes

The issue lies in the difference between %put and put.

Do you want to see the contents of the macro variable &var? Then use %put(&var).

If, however, you want to see the contents of the SAS data step variable whose name is stored in &var, then use put(&var).

As such I would rewrite this:

%macro test_func(var=);
put &var.;
%mend;

And now this works as you expect:

data test_data_step;
  value = 0;
  %test_func(var = value)
run;

(Note one other minor change - the removal of the ; after %test_func - it is unnecessary, and while usually not a big deal, it can cause problems if you get in the habit of putting it there.)