DATA Step, Macro, Functions and more

How to automate the email processing

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

How to automate the email processing

Data test;
Input id$ sales email$;
Cards;
aa 1000 xyz@gmail.com
bb 2000 raj@gmail.com
xx 9000 ggg@gmail.co;
Run;

Can someone kindly help me on this request.
I want to send first line info(aa 1000) to xyz@gmail.com and same way 2nd line info(bb 2000) to raj@gmail.com etc..

Accepted Solutions
Solution
2 weeks ago
Occasional Contributor
Posts: 6

Re: How to automate the email processing

Posted in reply to Bhargavi221

Here's what worked for me. Of course, double check your lengths on your cards on the email input. 

 Data test;
Input id$ sales email$33.;
Cards;
aa 1000 aaa@gmail.com
bb 2000 bbb@gmail.com
xx 9000 xxx@gmail.com
;
Run;
FILENAME outmail EMAIL /* Use filename and define outmail variable */
SUBJECT="TEST"	/* Email title */
FROM= "sender@domain.com"; /*Who from*/
options mprint mlogic symbolgen;
%macro email();
%let cnt=1;
	%do %until(&cnt > &sysnobs); /*do until the cnt is gt # of obs in your dataset*/
data _null_;  /*creates variables from your dataset for obs=cnt*/
set test (firstobs=&cnt obs=&cnt);
call symputx('id',id);
call symputx('sales',put(sales,dollar12.2));
call symputx('email',email);
run;
data _null_; /*send the email. play around with the put statements as needed.*/
file outmail TO=("&email");
put "&id  &sales";
run;
%let cnt = %eval(&cnt + 1); /*increments the count up 1*/
	%end;
%mend email;
%email

 

View solution in original post


All Replies
Solution
2 weeks ago
Occasional Contributor
Posts: 6

Re: How to automate the email processing

Posted in reply to Bhargavi221

Here's what worked for me. Of course, double check your lengths on your cards on the email input. 

 Data test;
Input id$ sales email$33.;
Cards;
aa 1000 aaa@gmail.com
bb 2000 bbb@gmail.com
xx 9000 xxx@gmail.com
;
Run;
FILENAME outmail EMAIL /* Use filename and define outmail variable */
SUBJECT="TEST"	/* Email title */
FROM= "sender@domain.com"; /*Who from*/
options mprint mlogic symbolgen;
%macro email();
%let cnt=1;
	%do %until(&cnt > &sysnobs); /*do until the cnt is gt # of obs in your dataset*/
data _null_;  /*creates variables from your dataset for obs=cnt*/
set test (firstobs=&cnt obs=&cnt);
call symputx('id',id);
call symputx('sales',put(sales,dollar12.2));
call symputx('email',email);
run;
data _null_; /*send the email. play around with the put statements as needed.*/
file outmail TO=("&email");
put "&id  &sales";
run;
%let cnt = %eval(&cnt + 1); /*increments the count up 1*/
	%end;
%mend email;
%email

 

PROC Star
Posts: 2,316

Re: How to automate the email processing

[ Edited ]
Posted in reply to Bhargavi221

Searching the web for 30 seconds brings up this:

 

filename reports email 'Jim';

data _null_;
  file reports;
  infile cards eof=lastobs;
  length name dept $ 21;
  input name dept;

     /* Assign the TO attribute      */
  put '!EM_TO!' name;
   
     /* Assign the SUBJECT attribute */
  put '!EM_SUBJECT! Report for ' dept;  
   
  put name ',';
  put 'Here is the latest report for ' dept '.';

     /* ATTACH the appropriate report */
  if dept='marketing' then
      put '!EM_ATTACH! mktrept.txt';
  else                                  
    
    put '!EM_ATTACH! devrept.txt';
  
     /* Send the message */
  put '!EM_SEND!';                      
    
    /* Clear the message attributes */
  put '!EM_NEWMSG!';                    
    
  return;

   /* Abort the message before the */ 
   /*   RUN statement causes it to */ 
   /*   be sent again.            */
lastobs: put '!EM_ABORT!';              
    
  datalines;
Susan          marketing
Jim            marketing
Rita           development
Herb           development
;
run;

 

 

Contributor
Posts: 72

Re: How to automate the email processing

[ Edited ]
Posted in reply to Bhargavi221
Data test;
infile cards dlm=" ";
Input id$ sales email$ 40.;
Cards;
aa 1000 xyz@gmail.com
bb 2000 raj@gmail.com
xx 9000 ggg@gmail.com
;

proc sql;
select count(distinct email) into :emailcnt from test;
%let emailcnt = %cmpres(&emailcnt);
select distinct email into :email1 - :email&emailcnt from test;
quit;

%macro mail;
%if &emailcnt gt 0 %then
%do i = 1 %to &emailcnt;
filename Madhu email
from = "Insert User Email Id Here"
subject = "Test"
to = "&&email&i"
type = "text/html";

data _null_;
file Madhu;
set Test(where = (email="&&email&i"));
put ID SALES ;
RUN;
%end;
%mend;
%mail;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 144 views
  • 2 likes
  • 4 in conversation