%include question

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

%include question

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.

 

 

 


Accepted Solutions
Solution
‎02-26-2018 06:05 AM
Super User
Posts: 23,771

Re: %include question

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


All Replies
Super User
Posts: 3,926

Re: %include question

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

Occasional Contributor
Posts: 13

Re: %include question

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.

Super User
Super User
Posts: 8,120

Re: %include question

[ Edited ]

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.

Solution
‎02-26-2018 06:05 AM
Super User
Posts: 23,771

Re: %include question

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.

 

 

 


 

Occasional Contributor
Posts: 13

Re: %include question

Thank you Reeza. I understand this a lot better now

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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