BookmarkSubscribeRSS Feed
jammy
Calcite | Level 5


Hi,

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

Thanks

11 REPLIES 11
FriedEgg
SAS Employee

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...?

jammy
Calcite | Level 5

it's initialized through an %include statement

Quentin
Super User

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).

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
FriedEgg
SAS Employee

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...

martha_sas
SAS Employee

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.

jammy
Calcite | Level 5

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!

SASKiwi
PROC Star

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.

FriedEgg
SAS Employee

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;

Tom
Super User Tom
Super User

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 ;

jaiganesh
Obsidian | Level 7

Could you please provide the particular syntax of %include to view the SAS Macro code in Log. I tried to locate the SAS Macro file in different ways, However could not succeed..

 

Library- Test123

Library Location ="C:\Users\jaiga\Desktop\SAS_Test_Practise\Macro"

Macro catalog name- SASMACR

Macro Name - Macro1

 

 

Kindly provide how to locate this macro using %include syntax.

 

Regards.

Jai

SASKiwi
PROC Star

I'm guessing but it is probably something like this:

 

%include "C:\Users\jaiga\Desktop\SAS_Test_Practise\Macro\Macro1.sas"

You can get the correct path by navigating to the folder in Windows Explorer then copying and pasting from the navigation bar at the top.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 5348 views
  • 3 likes
  • 7 in conversation