🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 06-06-2018 01:12 PM
(2931 views)
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..
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..
- Tags:
- automation
- sas
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;