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
PROC Star

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

Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.
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
Opal | Level 21

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
Opal | Level 21

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

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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