DATA Step, Macro, Functions and more

A question about using customer-defined macros

Reply
Contributor
Posts: 35

A question about using customer-defined macros

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.

Super Contributor
Posts: 1,636

Re: A question about using customer-defined macros

try adding

mautosource in options

Contributor
Posts: 35

Re: A question about using customer-defined macros

Thanks

I change the code as:

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

However, it does not work, either.

Respected Advisor
Posts: 3,124

Re: A question about using customer-defined macros

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

Super User
Posts: 5,082

Re: A question about using customer-defined macros

You're correct to use options sasautos=

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

Good luck.

Contributor
Posts: 35

Re: A question about using customer-defined macros

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.

Super Contributor
Posts: 1,636

Re: A question about using customer-defined macros

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


Super User
Posts: 5,082

Re: A question about using customer-defined macros

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?

Contributor
Posts: 44

Re: A question about using customer-defined macros

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

Super Contributor
Posts: 349

Re: A question about using customer-defined macros

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

Ask a Question
Discussion stats
  • 9 replies
  • 344 views
  • 0 likes
  • 6 in conversation