This is a follow up question to a previous post. I am trying to store a macro in a catalog as outlined by these articles, in addition to the resources cited in my original post:
Here is what I have done so far:
I have created a directory "C:\myMacros." First, I create a program called "HelloWorld.sas" which contains the following code:
/* HelloWorld.sas */
option mstored sasmstore=mymacros;
libname myMacros 'C:\myMacros';
%macro HelloWorld() / store source;
data _null_;
put "Hello, World!";
run;
%mend;
The code executes with the following log entry:
1 option mstored sasmstore=mymacros;
2 libname myMacros 'C:\myMacros';
NOTE: Libref MYMACROS was successfully assigned as follows:
Engine: V9
Physical Name: C:\myMacros
3
4 %macro HelloWorld() / store source;
5 data _null_;
6 put "Hello, World!";
7 run;
8 %mend;
Within the SAS File Explorer, the Active Library "Mymacros" has been created in which resides catalog named "Sasmacr". Checking within Windows Explorer, I see that "C:\myMacros\sasmacr.sas7bcat" has been created. In the SAS File Explorer, I click on the "Sasmacr" catalog and find "Helloworld" inside. When I double click on it, I get message box saying,
No default action for the Macro data type.
Therefore, I conclude that the macro has been compiled and stored in the "Sasmacr" catalog. I close out of SAS to clear all memory.
Now, I try to call the macro. I open a new SAS session and create a new program titled "CallHelloWorld1.sas" which contains the following code:
/* CallHelloWorld1.sas */
libname myMacros 'C:\myMacros';
filename myCat catalog 'mymacros.sasmacr.helloworld.source';
%include myCat;
%HelloWorld();
This generates an error at the %include
statement.
1 /* CallHelloWorld1.sas */
2 libname myMacros 'C:\myMacros';
NOTE: Libref MYMACROS was successfully assigned as follows:
Engine: V9
Physical Name: C:\myMacros
3 filename myCat catalog 'mymacros.sasmacr.helloworld.source';
4 %include myCat;
ERROR: Physical file does not exist, SOURCE .
ERROR: Cannot open %INCLUDE file MYCAT.
5
6 %HelloWorld();
-
180
WARNING: Apparent invocation of macro HELLOWORLD not resolved.
ERROR 180-322: Statement is not valid or it is used out of proper order.
The error claims that the physical file doesn't exist, which contradicts my observation of it above. So, I conclude that I am calling it incorrectly. According to FILENAME Statement, CATALOG Access Method, a SAS four part name consists of library.catalog.entry.entrytype. My statement consists of
myMacros
as defined by libname myMacros 'C:\myMacros';
sasmacr
helloworld
source
That is, mymacros.sasmacr.helloworld.source
. There must be an error in here, but I cannot fathom what it is.
To try another approach, again I close out of SAS to clear the memory. I create "CallHelloWorld2.sas" which contains the following code:
/* CallHelloWorld2.sas */
libname myMacros 'C:\myMacros';
filename myCat catalog 'mymacros.sasmacr';
%include myCat(HelloWorld);
%HelloWorld();
This too produces an error at the %include
line:
1 /* CallHelloWorld2.sas */
2 libname myMacros 'C:\myMacros';
NOTE: Libref MYMACROS was successfully assigned as follows:
Engine: V9
Physical Name: C:\myMacros
3 filename myCat catalog 'mymacros.sasmacr';
4 %include myCat(HelloWorld);
ERROR: Entry HELLOWORLD.SOURCE not found in catalog MYMACROS.SASMACR.
ERROR: Cannot %INCLUDE member HelloWorld in the aggregate MYCAT.
ERROR: Entry HELLOWORLD.SOURCE not found in catalog MYMACROS.SASMACR.
ERROR: Cannot %INCLUDE member HelloWorld in the aggregate MYCAT.
5
6 %HelloWorld();
-
180
WARNING: Apparent invocation of macro HELLOWORLD not resolved.
ERROR 180-322: Statement is not valid or it is used out of proper order.
It appears that either my macro has not been stored properly or that I am calling it incorrectly. However, the resources are woefully inadequate. Please help!
libname myMacros 'C:\temp';
option mstored sasmstore=mymacros;
%helloWorld()
That's all you need to do - remind SAS where you are pointing things and then run the macro. You don't need to %include anything.