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);
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.