Myself and many other colleagues use librefs to connect to several libraries on our server each time we run a program. In order to access the library, a password is required and is supplied using a prompt. Our problem is that you only get three chances to enter your password and then you are locked out, so if one accidentally enters their password while trying to connect to 3+ libraries, they are locked out on the first try. I am trying to use a macro to check whether there was an error after the first libref statement and if so, to exit the program before executing the second libref statement. If not, continue with the remainder of the program. I thought the macro below worked in the past but I am either mistaken, or something changed and it no longer works. Does anyone know how to acheive this?
%macro check_for_errors;
%if &syserr > 0 %then %do;
endsas;
%end;
%mend check_for_errors;
libname AECS DB2 datasrc=FDWXX schema=FDWATOM user=&u_alias password=&u_password;
%check_for_errors
libname ECS DB2 datasrc=FDWXX schema=FDWECS user=&u_alias password=&u_password;
Libname AE DB2 datasrc=FDWXX schema=FDWAE user=&u_alias password=&u_password;
libname QV DB2 datasrc=FDWXX schema=FDWQV user=&u_alias password=&u_password;
Are you looking for the LIBREF() function?
libname AECS DB2 datasrc=FDWXX schema=FDWATOM user=&u_alias password=&u_password;
%if %sysfunc(libref(AECS)) %then %do;
endsas;
%end;
Or perhaps just the ERRORABEND option?
options errorabend;
libname AECS DB2 datasrc=FDWXX schema=FDWATOM user=&u_alias password=&u_password;
Are you looking for the LIBREF() function?
libname AECS DB2 datasrc=FDWXX schema=FDWATOM user=&u_alias password=&u_password;
%if %sysfunc(libref(AECS)) %then %do;
endsas;
%end;
Or perhaps just the ERRORABEND option?
options errorabend;
libname AECS DB2 datasrc=FDWXX schema=FDWATOM user=&u_alias password=&u_password;
A better option might be to use the LIBNAME function then test the function return code which is 0 if the function worked successfully:
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.