Whenever we assign a libname (especially a libname to a database), we would want to be sure that the library path should be valid/existing. When it comes to assigning a libname to a database, example oracle, we may also want to confirm if the user-id and the password are valid.
Below is the syntax for doing a error check immediately after assigning a libname and before proceeding to access the lib reference:
libname dbase oracle user="USER_ID" pass="PASSWORD" path='@PATH' schema=MYSCHEMA;
filename sendmail email to=("Pramod.R@xyz.com");
%if &syslibrc = 0 %then %do;
/* RUN THE ACTUAL CODE HERE*/
file sendmail subject="Success";
put / "The code ran into completion.";
/* THROW THE ERROR MAIL */
file sendmail subject="Failed";
put / "The code ran into ran into problems due to Oracle connection problems.";
Similarly we can also do a check for the filename by using the automatic macro variable - %sysfilrc, which returns a 0 value for successful filename statement and a non zero value if the filename statement failed.