BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
Peter_C
Rhodochrosite | Level 12
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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 601 views
  • 0 likes
  • 3 in conversation