Help using Base SAS procedures

Email results as part of body

Reply
Contributor
Posts: 73

Email results as part of body

Hi everyone!

I am attempting to send email with the results of dataset as part of email body, not as attachment.

I've looked and looked but can't find something that works.

Please keep in mind i am new to SAS.

Thanks

Fred
Trusted Advisor
Posts: 2,113

Re: Email results as part of body

Fred,

This note, found by simply searching for email on support.sas.com has an example of putting SAS output into the text of an email.

http://support.sas.com/kb/19/767.html

As pointed out in responses to your last two queries, if you post more precise questions you will get more precise answers.

Doc Muhlbaier
Contributor
Posts: 73

Re: Email results as part of body

Sorry I was attempting to be clear.

I checked and read the info on the link you attached and it does not explain how to embed the results from a dataset into the email body.

Fred
Trusted Advisor
Posts: 2,113

Re: Email results as part of body

You were clear, just very incomplete. That is where you need an example. For instance, if you want to just put a listing of the data into the email, you could modify the code to PUT it out.

filename mymail email "your.emailaddress.com_or_edu" subject="test message";
data _null_;
SET MyDataSet;
file mymail;
PUT _all_=;
run; quit;

Not pretty, but it puts it all in the content of the e-mail.
Contributor
Posts: 73

Re: Email results as part of body

Hi Duke

Please see my code and below that the log error


filename mymail email "fred.standard@symptico.ca" subject="test
message";
data _null_;
SET ccar.count;
file mymail;
PUT _all_= ;
run; quit;

Log Error below

26 filename mymail email "fred.standard@sympatico.ca" subject="test
27 message";
28 data _null_;
29 SET ccar.count;
30 file mymail;
31 PUT _all_= hello;
-
22
ERROR 22-322: Expecting a name.

32 run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
real time 0.08 seconds
cpu time 0.00 seconds



32 ! quit;
SAS Super FREQ
Posts: 8,740

Re: Email results as part of body

Hi:
The syntax is just:
[pre]
put _all_;
[/pre]

you automatically will get named variables, i.e. name=Alfred sex=M in the output;

cynthia
Contributor
Posts: 73

Re: Email results as part of body

Thank you so much everyone for your help and patience, i got it to work.

Fred
Contributor
Posts: 73

Re: Email results as part of body

Hi again

One thing that is causing some confusion that maby you can help with.

_ERROR_=0 _N_=1 shows after the results in the email body, can you confirm what it means and suggest a way to suppress it?

Thank

Fred
Respected Advisor
Posts: 3,777

Re: Email results as part of body

[pre]
put (_all_)(=);
[/pre]
SAS Super FREQ
Posts: 8,740

Re: Email results as part of body

Hi...look at #3 example code in that link:
[pre]
filename mymail email "your.emailaddress.com_or_edu"
subject="test message";
data _null_;
file mymail;
put 'hello there';
run; quit;
[/pre]

What you would have to do is modify that data _null_ program to include the dataset the way you want. Something like this:
[pre]
filename mymail email "your.emailaddress.com_or_edu"
subject="test message";

data _null_;
set your.dataset_to_put_in_mail;
file mymail;
if _n_ = 1 then do;
/* <...PUT statements to write one time...> */
end;
/* <...PUT statements to write for every observation...> */
run; quit;
[/pre]

However, I think that it really is better to put the dataset results into an attachment using an ODS method like this:
http://support.sas.com/kb/24/972.html

Because then the folks can save the attachment or open it and save it as they want. You can use ODS to create HTML, CSV, RTF, PDF or Spreadsheet Markup Language XML version of the dataset.

cynthia
Occasional Contributor
Posts: 9

Re: Email results as part of body

Hi Cynthia,

in my case I have 2 rows in my dataset, but in email body only shows the first row. Could you please help?

 

 

Thanks,

Fran

N/A
Posts: 1

Re: Email results as part of body

I used the same code to send the contents of the dataset in the body of email. My Requirement is, I m producing a report in Mainframe, which is stored in Dataset and need to send the contents of the dataset in email.

WARNING: Apparent symbolic reference CC not resolved.                     

NOTE: Line generated by the invoked macro "EMAIL".                        
5       DATA NULL;SET SPT.SCHEDULE.JOBS.HISTORY;FILE OUTMAIL ;PUT ALL=; RUN ;
                          _________________________                   
                          211                                         
ERROR: File WORK.SCHEDULE.DATA does not exist.                            
                                                                          
ERROR 211-185: Invalid data set name.        

SAS Macro :

%MACRO EMAIL;                                     
                                                   
** SEND AN EMAIL TO INDICATE THE REPORT IS READY ;
FILENAME OUTMAIL EMAIL                            
TO=("&TO.")                                       
CC=("&CC.")                                       
FROM=("&FROM.")                                   
SUBJECT=&SUBJECT;                                 
                                                   
DATA NULL;                                        
SET SPT.SCHEDULE.JOBS.HISTORY;                 
FILE OUTMAIL ;                                 
PUT ALL=;                                      
RUN ;                                             
                                                   
                                                   

  %MEND EMAIL ;                                                                  

Ask a Question
Discussion stats
  • 11 replies
  • 1396 views
  • 0 likes
  • 6 in conversation