Help using Base SAS procedures

How view macro code, without invoking?

Reply
Occasional Contributor
Posts: 15

How view macro code, without invoking?


Hi,

Is it possible view a macro's code when you have the name, without invoking it?

Thanks

Trusted Advisor
Posts: 1,301

Re: How view macro code, without invoking?

The method in which to view it depends upon it how it has been placed into you session.  Do you know if the macro is initialized through an autocall library or a compiled catalog, a %include statement, etc...?

Occasional Contributor
Posts: 15

Re: How view macro code, without invoking?

it's initialized through an %include statement

PROC Star
Posts: 1,322

Re: How view macro code, without invoking?

You have a %include statement pointing to the source code for the macro (a .sas file)?

You can open that .sas file in a text editor (inlcuding a program editor).

Trusted Advisor
Posts: 1,301

Re: How view macro code, without invoking?

I just realized that maybe the question is, can I view the code generated by a macro without invoking it?  If this is the case, the most simplistic answer is, no.

If this is not the case, as Quentin said, since you are using the %include, you already have the explicit path to the macro program, so, just open if up in you preferred text editor for SAS code and take a look...

SAS Employee
Posts: 19

Re: How view macro code, without invoking?

Is the question about a stored macro, and you know where it is stored?   If so, there is a way to do it.

Suppose I created a macro called mymacro and stored it in a library in C:\macrolib.

In a later SAS session I want to see what code is in that macro.

I can do that, without invoking the macro,  by using %copy.

Example:

options mstored sasmstore=mylib;

libname mylib "C:\macrolib";

%copy mymacro/source;

The macro code will be in the SAS  log. The macro is not invoked.

Occasional Contributor
Posts: 15

Re: How view macro code, without invoking?

Posted in reply to martha_sas

there are a number of include statements which all contain macros.  I was just seeing if I could bring up the code for one instead of hunting it down!

Super User
Posts: 3,256

Re: How view macro code, without invoking?

If you are using Display Manager you could convert your %include statements to dm 'include'. For example: dm "include 'c:\mymacro' "; This will bring the code into the SAS editor without running it.

Trusted Advisor
Posts: 1,301

Re: How view macro code, without invoking?

You could also read the catalog's macro entry, however, due to the quoting obfuscations it can get fairly messy:

%include '/path/to/MACLIB.sas';

/* default work macro catalog is work.sasmacr, if you are using enterprise guide then it is sasmac1 instead, by default */

filename x catalog 'work.sasmac1.YOUR MACRO NAME HERE.macro' ;

data _null_;

infile x;

input;

put _infile_;

run;

Super User
Super User
Posts: 7,060

Re: How view macro code, without invoking?

Set the SOURCE2 option of add / SOURCE2 option to the %INCLUDE statements and you will see the macro code in the SAS log when the %INCLUDE statement runs.

options source2 ;

%include 'mymacro.sas';

or

%include 'mymacro.sas' / source2 ;

Ask a Question
Discussion stats
  • 9 replies
  • 428 views
  • 1 like
  • 6 in conversation