BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Bhargavi221
Fluorite | Level 6
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..
1 ACCEPTED SOLUTION

Accepted Solutions
bobpep212
Quartz | Level 8

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

3 REPLIES 3
bobpep212
Quartz | Level 8

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

 

ChrisNZ
Tourmaline | Level 20

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;

 

 

MadhuKorni
Quartz | Level 8
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;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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