0
votes

I am using SAS Enterprise Guide 6.1 and am utilizing the "Submit SAS Code when server is connected" capability under Tools, SAS Programs to submit all of my personal credentials, libnames. Yes, I know there is probably an easier way to do this with SAS Management Console, but that is not an option right now.

I have several Teradata libraries I need to assign within each project, but the problem is that sometimes I (or more commonly somebody else on my team) will change my password and forget to change it in the start-up code. This results in several incorrect attempts and locks me out immediately. I wish to do a few things:

  1. Create a conditional libname assignment that will execute all the libnames if the credentials are correct.

  2. If the credentials are incorrect, the libnames are not executed (so that I don't lock myself out).

  3. Since the SAS code in the "Submit SAS Code when server is connected" section doesn't seem to generate a log, I wish to send myself an email with the SAS Log attached (only if the credentials fail).

  4. Kill the Server connection (if credentials error out) to avoid further attempts to assign libraries.

Here is my attempt, I'm having trouble attaching the log and setting up the email statement.

*Define personal credentials;
%let [email protected];
filename temp email "&myemail"; 

*Define Teradata credentials;
%let tera_user=Gollum;                         /*Teradata Username*/
%let tera_pwd=#filthy_hobbitses;                         /*Teradata Password*/

*Conditionally assign libraries;
%macro libsetup();
libname library1 teradata user=&tera_user password="&tera_pwd" tdpid=terap schema=library1 fastload=yes bulkload=yes fastexport=yes;
    %if &syslibrc=0 %then
        %do;
            libname library2 teradata user=&tera_user password="&tera_pwd" tdpid=terap schema=library2 fastload=yes bulkload=yes fastexport=yes;
            libname library3 teradata user=&tera_user password="&tera_pwd" tdpid=terap schema=library3 fastload=yes bulkload=yes fastexport=yes;
            *more library statements here;
        %end;
    %else 
        %do;
            data _null_;
            file temp
            subject="TERADATA CREDENTIALS ERROR"
            attach=("put SAS LOG filename here");
            put 'Teradata Login Failed.  SAS LOG Attached.';
            %abort abend;
        %end;
%mend libsetup;
%libsetup;

Thanks.

1
Sometimes its easier to use the libname function instead of libname statements as well.Reeza
If you're going to embed passwords in code, use PROC PWENCODE to encrypt it, then embed the encrypted value (e.g. %LET TERA_PWD = {sas002}ax=5qZhw4... ;) in your code.Chris J

1 Answers

0
votes

Can't tell if your looking for suggestions on alternative approaches, or for help with the emailing.

For emailing, something like below (untested) should work:

filename __mymail email
  to="[email protected]"
  from="[email protected]"
  subject="credential error"
  attach="/home/mylog.log"
;

data _null_;
  file __mymail;
  put "Hi!";
run;

Note the server where SAS is executing has to have access to a mail server, and actual code needed may vary with mail protocol, etc.

For attaching the log, will probably need to use PROC PRINTTO to write your log to a file, and then use PROC PRINTTO again to let go of the file before you email it.

HTH