I have a Data _Null_ step [see (2) below] that
(1) creates a macro variable &PATH containing a SAS library name.
(2) performs a call execute statement on macro MMM1 [see (1) below].
Macro MMM1 allocates a Library "LIB" based on the data contained in &PATH & then performs a Proc sort on a file in the named Library.
Problem :- sometimes the Library does not exist and so, consequently, the Proc sort fails.
When the Libname statement creates a Library that does not exist, a "note" to that effect appears in the SAS log.
When the Proc statement executes, it (understandably) causes a SAS error.
How can I use the SAS system return codes to trap the "note" warning about the Library not existing to prevent the subsequent Proc sort from executing?
/** (1) **/
LIBNAME LIB "&PATH";
PROC SORT DATA=LIB.filename;
/** (2) **/
Attrib PATH Length=$40;
PATH = '/DIR1/DIR2/'||Part3||'/DIR4/';
Call execute('%MMM1(PATH=' || PATH || ')');
There is a lot of general info on SYSRC in the SAS manuals, in particular something called _SWNOLIB looks very promising. Its probably very straightforward, but there are not enough "examples" in the manuals (for me) to be able to decipher how to actually make it work.
Depending on your OS, review the SAS functions such as FILEEXIST (as well as other like-purpose functions) and you can use %SYSFUNC with one of these functions in a macro. If you want to maintain your DATA step outside the macro, set a %GLOBAL statement at the start of your macro and test the "&MYGLOBAL" in a DATA step IF, placed "BEFORE" the SET statement, and issue a STOP when you have detected that the path does not exist.
Also, consider that the entire DATA step could be executed within your macro, using SAS macro language SAS data member read functions, FOPEN, FREAD, FCLOSE.
Suggest you scan the SAS.COM support site for examples and SUGI/SGF papers on these topic-areas; also there is a related link pasted below.