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.
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.
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:
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.
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.
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.
Thank you Reeza. I understand this a lot better 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!
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.
Ready to level-up your skills? Choose your own adventure.