How to store SAS Macros in a permanent Library?
eg:
%macro import(set,sh,op);
proc import datafile="D:\SAS Docs\CDM Docs\Protocol.xlsx" dbms=xlsx out=&set replace;
sheet=&sh;
getnames=&op;
run;
proc print data=&set;run;
%mend;
This is a macro but it is getting stored in Work Library. I want to store it in a permanent Library. How?
Store the macro as code in your autocall library.
Read the documentation that I linked in my previous post. If you have specific questions, ask them.
It is possible to store COMPILED macros into catalogs and tell SAS to look for them there.
But it is much easier to create and manage if you use the SASAUTOS facility instead. Use the SASAUTOS option to point to a folder (or series of folders) where SAS can look for an auto-compile the macro from the source. Place each macro in its own individual file. Name the file with the name of the macro with .sas extension. Make sure to use lowercase letters for the filename. So your example should be stored in a file named import.sas.
Please explain the Syntax of Sasautos in SAS environment.
@Rakesh93 wrote:
Please explain the Syntax of Sasautos in SAS environment.
Make a directory on you filesystem. For example
/home/me/sas_macros/
Make a macro and store it in a file in that directory. For example a macro name %MyMac() might be in a file named.
/home/me/sas_macros/mymac.sas
And have content like:
%macro MyMac(dsname);
proc contents data=&dsname;
run;
%mend MyMac;
Then in your main program add this line to tell SAS where to find the macros:
options insert=(sasautos=('/home/me/sas_macro'));
And then after than in your main program you just call the macro.
%mymac(sashelp.class)
If you have called it before it just runs, but if not then SAS will search the folders in the SASAUTOS option tor the file named 'mymac.sas' and include it. Then, now that the macro has been compiled, it calls it.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.