BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
vseshad
Calcite | Level 5

Can I create a macro1 with a %include statement referencing macro2 that is stored in macro catalog location? Or do I need to store macro2 as a sas file for me to be able to use %include statement?

 

For example: 

options mstored sasmstore=test;

libname test "c:/desktop/test";

 

%macro macro1/store source;

 proc print data=test;

run;

%mend;

 

%macro macro2;

%include "c:\desktop\macro1.sas";  <----- Is is possible for me to refer to macro1 like this? Or should I save all the above code in a file    %mend;                                                    and refer that file?

 

Thank you.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Can I create a macro1 with a %include statement referencing macro2 that is stored in macro catalog location?

 

It depends on if the catalog is available. If you have it in a library that isn't assigned it won't work for example. 

 

I would personally recommend saving each macro into a .sas file and then putting them into a folder. You can then %INCLUDE all macros in that folder using:

 

%include "C:\_localdata\SASMacros\*.sas";

 

Or you can create the auto call library as indicated already. The documentation may seem confusing, but it's quite straightforward.

In that case, you save each macro into a file, with the macro name as the file name. Then specify:

 

option sasautos='path to folder with macros';

@vseshad wrote:

Can I create a macro1 with a %include statement referencing macro2 that is stored in macro catalog location? Or do I need to store macro2 as a sas file for me to be able to use %include statement?

 

For example: 

options mstored sasmstore=test;

libname test "c:/desktop/test";

 

%macro macro1/store source;

 proc print data=test;

run;

%mend;

 

%macro macro2;

%include "c:\desktop\macro1.sas";  <----- Is is possible for me to refer to macro1 like this? Or should I save all the above code in a file    %mend;                                                    and refer that file?

 

Thank you.

 

 

 


 

View solution in original post

5 REPLIES 5
SASKiwi
PROC Star

If you want to store your macros in separate files then I would highly recommend you set up a macro AUTOCALL library. You don't need to use %INCLUDE with these at all - SAS will search for them automatically:

http://documentation.sas.com/?docsetId=mcrolref&docsetTarget=n1o5fkxq0gqdpcn1xs3ksdks69tf.htm&docset...

vseshad
Calcite | Level 5

Thank you for your reply.  I am trying to understand what would be the best way to use %include to refer a macro. I understand from your reply that %include isn't the best solution to refer a stored macro but if I still want to use %include, how would I go about doing it? Thank you again for your reply. Users such as yourself are a huge help to novices like me.

Tom
Super User Tom
Super User

The %INCLUDE command reads in lines of code. So to "%include" a macro you need have a text file with the SAS code to define the macro.  So make a file that looks like

%macro mymacro 
....
%mend;

Then in the program where you want have the macro defined you use

%include FILENAME;

SAS has a lot of ways to refer to source of the text lines, including source members in SAS catalogs. The easiest is just to use a quoted physical file name.

Reeza
Super User

Can I create a macro1 with a %include statement referencing macro2 that is stored in macro catalog location?

 

It depends on if the catalog is available. If you have it in a library that isn't assigned it won't work for example. 

 

I would personally recommend saving each macro into a .sas file and then putting them into a folder. You can then %INCLUDE all macros in that folder using:

 

%include "C:\_localdata\SASMacros\*.sas";

 

Or you can create the auto call library as indicated already. The documentation may seem confusing, but it's quite straightforward.

In that case, you save each macro into a file, with the macro name as the file name. Then specify:

 

option sasautos='path to folder with macros';

@vseshad wrote:

Can I create a macro1 with a %include statement referencing macro2 that is stored in macro catalog location? Or do I need to store macro2 as a sas file for me to be able to use %include statement?

 

For example: 

options mstored sasmstore=test;

libname test "c:/desktop/test";

 

%macro macro1/store source;

 proc print data=test;

run;

%mend;

 

%macro macro2;

%include "c:\desktop\macro1.sas";  <----- Is is possible for me to refer to macro1 like this? Or should I save all the above code in a file    %mend;                                                    and refer that file?

 

Thank you.

 

 

 


 

vseshad
Calcite | Level 5

Thank you Reeza. I understand this a lot better now

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1152 views
  • 1 like
  • 4 in conversation