BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mnvandyke06
Calcite | Level 5

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

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;
mnvandyke06
Calcite | Level 5
Libname was exactly what i was looking for. Thank you!!
SASKiwi
PROC Star

A better option might be to use the LIBNAME function then test the function return code which is 0 if the function worked successfully:

https://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=p1bq8nyxm7y1ygn1i4vyf82z68ls.htm...

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 519 views
  • 0 likes
  • 3 in conversation