SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
bigbigben
Obsidian | Level 7

Hi, I have a question about how to use customer-defined macros stored in a local directory. I learn that there are two methods: specify the "autocall macro libraries" or use %include to inclue an external file. Both of them look easy. However, I have no problem with the second method, but never worked the first out.

I saved some written macros as .sas file in a directory. For example, in the directory D:\work\sasfiles, there is a file named xxx.sas. Inside the file, there is just a simple macro defined:

%macro xxx;

   <command lines>

%mend xxx;

I then write the following lines in the main program :

options sasautos=("D:\work\sasfiles" sasautos);

%xxx;

As long as I run the main progrm, there is an error message: Warning: Apparent invocation of macro xxx not resolved.

However, If I write

%include "D:\work\sasfiles\xxx.sas";

%xxx;

The code runs perfectly.

My understanding is that I only need to specify a directory for the auto libraries (sasautos). This is what I want, since I have multiple macros saved in the same directory.

I work with SAS9.2 in a unix enviroment.

Thank you for your help.

9 REPLIES 9
Linlin
Lapis Lazuli | Level 10

try adding

mautosource in options

bigbigben
Obsidian | Level 7

Thanks

I change the code as:

options mprint sasautos=( "D:\work\sasfiles\xxx.sas" sasautos ) mautosource;

However, it does not work, either.

Haikuo
Onyx | Level 15

Since LinLin has answered your question, I will just pick on you a little:

You said: "I learn that there are two methods".

Not quite. There are actually another way to store and run customer-defined macros. You can compile-store and then call the compiled macro to run. comparing to the two methods you mentioned, this is most efficient to run a macro repeatedly (and more secure if you don't want your code being seen by other users). Search SAS help for details.

Regards,

Haikuo

Astounding
PROC Star

You're correct to use options sasautos=

But remove the second "sasautos" from inside the parentheses.

Good luck.

bigbigben
Obsidian | Level 7

Hi, guys:

Thanks for the responses. However, it still doesn't work if I remove the word sasautos in the parentness. I did so before, since I don't want to overwrite the default sas auto libraries.

Linlin
Lapis Lazuli | Level 10

Hi,

I use PC sas.

first I saved the code below at 'C:\TEMP\forum' as plast.sas

%macro plast;

data class;

   set sashelp.class;

   proc print data=&syslast;

   run;

%mend;

I call the macro by:

options mautosource sasautos=('C:\TEMP\forum',sasautos);

%plast


Astounding
PROC Star

Hmmm ...

Ben, your code does look correct but ...

You say you are running on Unix.  Yet the path in quotes is a path on the PC.  Do you have some sort of hybrid environment where the Unix machine can't find the folder?  Are you getting any error messages related to the OPTIONS statement?

JasonDiVirgilio
Quartz | Level 8

You may have to try something like this on Unix:

options sasautos=('/my/unix/directory', '!SASROOT/sasautos');

...or try assigning it to a FILENAME first:

filename mylib "d:\work\sasfiles\xxx.sas";

options sasautos=(sasautos, mylib);

I'm not sure if the order maters, but I always specify the sasautos fileref first, then a local fileref.

Also...there's a note in the documentation about SASAUTOS not recognizing upper case or mixed case filenames in Unix.

http://support.sas.com/kb/00/444.html

shivas
Pyrite | Level 9

Hi.

Try this...

first code: and save it.

%macro test;

%let USER_UMACRO_PATH =F:\Community_SAS;

%put &USER_UMACRO_PATH;

options sasautos=("&USER_UMACRO_PATH" %sysfunc(getoption(SASAUTOS)));

%mend test;

Second go to sasv9.cfg file and add you autocall library path(see the last line i have modified):

-SET SASAUTOS  (

                "!sasext0\core\sasmacro"

                "!sasext0\assist\sasmacro"

                "!sasext0\eis\sasmacro"

                "!sasext0\ets\sasmacro"

                "!sasext0\graph\sasmacro"

                "!sasext0\iml\sasmacro"

                "!sasext0\or\sasmacro"

                "!sasext0\qc\sasmacro"

                "!sasext0\share\sasmacro"

                "!sasext0\stat\sasmacro"

  "F:\Community_SAS"

               )

Now close sas editor and reopen the new one and check by invoking the macro...

%test;

Hope it helps..

Thanks,

Shiva

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 9 replies
  • 2317 views
  • 0 likes
  • 6 in conversation