DATA Step, Macro, Functions and more

Using SAS system return codes to control processing

Reply
N/A
Posts: 0

Using SAS system return codes to control processing

Hi Guys.

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.

Question :
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) **/
%MACRO MMM1(PATH=);
Data _NULL_;
LIBNAME LIB "&PATH";

PROC SORT DATA=LIB.filename;
BY DATETIME;
RUN;
run;
%MEND MMM1;


/** (2) **/
DATA _NULL_;
Attrib PATH Length=$40;
SET IN_REC(KEEP=Part3);
PATH = '/DIR1/DIR2/'||Part3||'/DIR4/';
Call execute('%MMM1(PATH=' || PATH || ')');
RUN;

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.


Thanks in advance for any advice
Super Contributor
Super Contributor
Posts: 3,174

Re: Using SAS system return codes to control processing

Posted in reply to deleted_user
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.

Scott Barry
SBBWorks, Inc.


http://support.sas.com/documentation/cdl/en/lrdict/59540/HTML/default/a000210912.htm
Valued Guide
Posts: 2,177

Re: Using SAS system return codes to control processing

Posted in reply to deleted_user
A libname statement sets the automatic macro variable &SYSLIBRC

have a look at it's online doc....
http://support.sas.com/documentation/cdl/en/mcrolref/59526/HTML/default/a000543774.htm .

PeterC
Ask a Question
Discussion stats
  • 2 replies
  • 127 views
  • 0 likes
  • 3 in conversation