DATA Step, Macro, Functions and more

Print Macro value to output window

Reply
Super Contributor
Posts: 673

Print Macro value to output window

How to print the macro value after it is resolved to output window. Usually we see it in the log window.
N/A
Posts: 0

Re: Print Macro value to output window

would this be satisfactory?[pre] data _null_ ;
* to print the value of macro variable named in &var;
file print ;
put "&var=" "&&&var" ;
stop ;
run;[/pre]Or, to print the values of all, with their current scope[pre] proc sort data= sashelp.vmacro out= _data_ ;
by scope name offset ;
run ;
proc print ;
by scope ;
id name ;
var offset value ;
run;[/pre]

try it to see.

PeterC
Super Contributor
Posts: 673

Re: Print Macro value to output window

Posted in reply to deleted_user
It works!
%macro test;
data _null_ ;
* to print the value of macro variable named in &var;
file print ;
put "&var=" "&&&var" ;
stop ;
run;
%mend test;
%test;
N/A
Posts: 0

Re: Print Macro value to output window

Rather than examine macro variable values in the output window, I just press a function key programmed to show my version of SASHELP.VMACRO in a viewtable window (or whenever the client's licence permits, in an FSview window because customising that is simpler) . The command is just [pre] vt sashelp.vmacro colheading=name[/pre]
I prefer the list to be ordered, so keep a view in my sasuser folder that is similar to the SASHELP.VMACRO view[pre] proc sql ;
create view sasuser.vmacro as
select scope as s format=$2.
, name format=$15.
, offset/200 as off format= 3.
, value format= $40.
, scope
, offset
from sashelp.vmacro
order by scope descending, name, offset
;
quit ;[/pre] The differences I introduced are as follows:
To most quickly locate any macro variable, I prefer the view to list names in order. Sorting first by "scope descending" places my macro variables before those which are automatic. If I should use this view within a macro, SCOPE names the macro in which each macro var was created. As sashelp.VMACRO predates SAS7 the 200 width limit is respected and a wide value is broken in 200 byte chunks and OFFSET is the real offset. Providing a narrower space for that value in my window, my view divides offfset by 200.

Then rather than submit code to review macro variable values, I just press a function key that issues command [pre] vt sasuser.vmacro colheading=name[/pre] or [pre] fsview sasuser.vmacro ; formula [/pre] ("formula" command in an FSView window retrieves customisation I prepared earlier, controlling window contents - column sizes, colors and order, and window size & position.
Some users like a mouse alternative to function keys, and prepare the command behind a new icon they create in the toolbar. Then they can easily view the current state of all macro variables at the touch of a button.
I guess (hope) there is something similar with E.G.

PeterC
Ask a Question
Discussion stats
  • 3 replies
  • 7631 views
  • 0 likes
  • 2 in conversation