Desktop productivity for business analysts and programmers

Error Handling with mail body

Reply
Contributor
Posts: 31

Error Handling with mail body

below code i am trying to execute but im not getting mails as mentioned in this code ...any one can tell whts wrong on this code,,

%MACRO MAIL;

filename myfile "D:/LOG/&sysdate _ &systime _log.txt" ;

proc printto log=myfile;

run;

%if &SYSerr =0 %then %do;

FILENAME outmail EMAIL

    SUBJECT="generated succesfully"

    FROM="....." to="..........";

FILE outmail;

    PUT  "Dear Sir/Madam";

    PUT " ";

    PUT "Report generated succesfully";

    RUN;

%end;

    %ELSE %IF &SYSerr > 1  %THEN %DO;

/*this is mail body to send mails */

FILENAME outmail EMAIL

    SUBJECT="report generated"

    FROM="................" to="................."

    attach="D:/LOG/&sysdate _ &systime _log.txt";

    FILE outmail;

    PUT  "Dear Sir/Madam";

    PUT " ";

    PUT "ERROR OCCURED";

    RUN;

      %END;

%MEND;

%MAIL;

Thanks in advance

Trusted Advisor
Posts: 2,114

Re: Error Handling with mail body

Tell us more. 

You posted to the EGuide forum.  Are you doing this through eguide? 

Is your SAS server local? 

The e-mail task in EGuide uses the client; does that work?

Are you getting any error or other messages in the log?

Do you have e-mail access from the server at all? 

Can you send email without the macro part?

What are your mail settings (from PROC OPTIONS)?

There are so many moving parts with e-mail that your code might be good, but the process breaks elsewhere.

Doc Muhlbaier

Duke

Contributor
Posts: 31

Error Handling with mail body

first thanks for ur replay...Duke

I am using this code in SAS EG with SAS MAIN Server and ,no i am unable to see log because of printto procedure

Yes i have mail acess.with out macro's i am able to send mails

i'm not using any mail options

Thank You,

Ramesh

Respected Advisor
Posts: 4,137

Re: Error Handling with mail body

I believe one possible cause is that &systime will resolve to something with a column ':' in it.

filename myfile "D:/LOG/&sysdate _ &systime _log.txt" ;

A column is not a valid character for names in Windows so things will go wrong there already.

I would suggest that as a first step you put your "filename ..., proc printto" in comment and use some other file for attachement. Then run the code and let us know if this works - or what the log tells you.

Regular Contributor
Regular Contributor
Posts: 166

Re: Error Handling with mail body

Hi,

Please check something...

You seem to be on a BI server platform.....

so instead of defining a path to windows try changing ur filename path to a path on your server

also i think the proc printto will create a .log file and not a .txt  so you might have to change your extension too....

I cannot test any of this as of now ..... so would hope it helps..

%MACRO MAIL;

filename myfile "/myserverpath/LOG/&sysdate _ &systime _log.log" ;

proc printto log=myfile;

run;

%if &SYSerr =0 %then %do;

FILENAME outmail EMAIL

    SUBJECT="generated succesfully"

    FROM="....." to="..........";

data _null_;

FILE outmail;

    PUT  "Dear Sir/Madam";

    PUT " ";

    PUT "Report generated succesfully";

    RUN;

%end;

%ELSE %IF &SYSerr > 1  %THEN %DO;

/*this is mail body to send mails */

FILENAME outmail EMAIL

    SUBJECT="report generated"

    FROM="................" to="................."

    attach=/myserverpath/LOG/&sysdate _ &systime _log.log;

data _null_;

    FILE outmail;

    PUT  "Dear Sir/Madam";

    PUT " ";

    PUT "ERROR OCCURED";

    RUN;

      %END;

%MEND;

%MAIL;

Occasional Contributor
Posts: 14

Re: Error Handling with mail body

I think the first thing to do is make sure the log is being generated. Then review the log to see if that points to your problem. Also, try removing the macro if logic and just generate an e-mail when the macro is run.

If you get all the way to generating an e-mail...then the problem could be diagnosed from your code.

Ask a Question
Discussion stats
  • 5 replies
  • 194 views
  • 0 likes
  • 5 in conversation