Hello,
Suppose that my mainfunction call m1, m2 , m3, m4
ex:
%macro mainfunc; %m1; %m2; %m3; %m4; %m5; %mend mainfunc; %mainfunc;
So imagine that in m3, for example, I need to make a libname statement and if the libname does not exist, how can I abort the %mainfunc;
I have found a good example on the web:
%macro libexits(libref); %if %sysfunc(libref(&libref)) %then %do; %put "&libref. does not exist"; %abort ; %end; %else %do; %put "the path of &libref. is : %sysfunc(pathname(&libref.))"; %end; %mend libexits; %libexits(test);
"Does not exist" as in it was supposed to exist before the macro or program runs and doesn't?
Or it was supposed to made in the macro and fails (for some reason)?
Check function LIBREF() .
Examples This example verifies a libref. If an error or warning occurs, the message is written to the log. Under some operating environments, the user can assign librefs by using system commands outside the SAS session. %if (%sysfunc(libref(sashelp))) %then %put %sysfunc(sysmsg());
I have found a good example on the web:
%macro libexits(libref); %if %sysfunc(libref(&libref)) %then %do; %put "&libref. does not exist"; %abort ; %end; %else %do; %put "the path of &libref. is : %sysfunc(pathname(&libref.))"; %end; %mend libexits; %libexits(test);
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.