BookmarkSubscribeRSS Feed
fredbell
Fluorite | Level 6
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
11 REPLIES 11
Doc_Duke
Rhodochrosite | Level 12
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
fredbell
Fluorite | Level 6
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
Doc_Duke
Rhodochrosite | Level 12
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.
fredbell
Fluorite | Level 6
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;
Cynthia_sas
SAS Super FREQ
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
fredbell
Fluorite | Level 6
Thank you so much everyone for your help and patience, i got it to work.

Fred
fredbell
Fluorite | Level 6
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
data_null__
Jade | Level 19
[pre]
put (_all_)(=);
[/pre]
Cynthia_sas
SAS Super FREQ
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
guanf
Calcite | Level 5

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

Viggy
Calcite | Level 5

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 ;                                                                  

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 11 replies
  • 7400 views
  • 0 likes
  • 6 in conversation