SAS FAQ #64: Calling SAS macros on UNIX systems
source: http://ssc.utexas.edu/consulting/answers/sas/sas64.html
Question:
On UNIX how do I call an external SAS MACRO that is in another file and not physically included in my SAS program?
Answer:
Put the SAS MACRO in a file having a name "macro_name.sas", where "macro_name" is the macro name from the SAS %MACRO statement.
When you want to use this macro in a SAS program, perform the following steps:
1) Use a FILENAME statement of the form:
FILENAME wheremac 'dir';
where "wheremac" is a fileref pointing to the directory where the macro file is stored, and "dir" is the directory path to where the macro file is stored.
2) Use an OPTIONS statement of the form:
OPTIONS SASAUTOS=wheremac;
to point to the directory containing the macro file.
3) Use a call for your macro as you normally would with the "%macroname" specification, where "macroname" is the first name of the macro file (and the name of the macro in the %MACRO statement).
For example if you had a macro to do a PROC PRINT stored in a file called "prt.sas", it could look like this:
%MACRO prt;
PROC PRINT;
RUN;
%MEND;
If you stored this file in your $HOME directory, you could run the SAS job:
FILENAME wheremac '$HOME/';
DATA one;
INPUT a b ;
CARDS;
1 23 2;
OPTIONS SASAUTOS=wheremac;
%prt
The above code will create the data set and print the data to the SAS listing file.
source: http://ssc.utexas.edu/consulting/answers/sas/sas64.html
Question:
On UNIX how do I call an external SAS MACRO that is in another file and not physically included in my SAS program?
Answer:
Put the SAS MACRO in a file having a name "macro_name.sas", where "macro_name" is the macro name from the SAS %MACRO statement.
When you want to use this macro in a SAS program, perform the following steps:
1) Use a FILENAME statement of the form:
FILENAME wheremac 'dir';
where "wheremac" is a fileref pointing to the directory where the macro file is stored, and "dir" is the directory path to where the macro file is stored.
2) Use an OPTIONS statement of the form:
OPTIONS SASAUTOS=wheremac;
to point to the directory containing the macro file.
3) Use a call for your macro as you normally would with the "%macroname" specification, where "macroname" is the first name of the macro file (and the name of the macro in the %MACRO statement).
For example if you had a macro to do a PROC PRINT stored in a file called "prt.sas", it could look like this:
%MACRO prt;
PROC PRINT;
RUN;
%MEND;
If you stored this file in your $HOME directory, you could run the SAS job:
FILENAME wheremac '$HOME/';
DATA one;
INPUT a b ;
CARDS;
1 23 2;
OPTIONS SASAUTOS=wheremac;
%prt
The above code will create the data set and print the data to the SAS listing file.
Call system routine, percentages system micro statements, and using UNIX environment variables within SAS programs.
ReplyDelete