BookmarkSubscribeRSS Feed
susana_alves
Calcite | Level 5

Hi!

 

I have to send an email as follows:

 

data _null_;
file sendit email
to=("&email_address")
subject="TEST";
put "Hello";
run;

 

However I have to send for more than one email. E-mail addresses are in a table with email and group fields. Example:

 

email   group

   A          X

   B         X

 

I want to extract from the table the emails that belong to the same group but I am only able to extract the first email (in this case A). I have tried to create an array but when I put the array as the variable &email_address I can not send the mail. The email addresses should look like this: "A" "B".

 

Is there any way to parameterize the sending of the email so that the emails of the people to whom I want to send the mail are extracted from the table? 

 

Thank you for your help!

3 REPLIES 3
tsap
Pyrite | Level 9

An easy solution is to use a PROC SQL step to create a macro variable containing a list of values from a specific table.

DATA WORK.Have;
FORMAT 		emailaddr $50.; 
INFORMAT	emailaddr $50.; 
INPUT  		emailaddr; 
CARDS;      
AdamApple@gmail.com
BillBobington@yahoo.com
ChuckCooper@hotmail.com
;

PROC SQL NOPRINT;
	SELECT	CAT('"',STRIP(emailaddr),'"')	AS QtdEmail		INTO :EmailAddrList Separated by ' '
	FROM WORK.Have;
QUIT;

%PUT &=EmailAddrList.;

When the new macro variable, 'EMAILADDRLIST' resolves, it looks like this (in the log):

EMAILADDRLIST="AdamApple@gmail.com" "BillBobington@yahoo.com" "ChuckCooper@hotmail.com"

 

So in your current logic, all you would then need to do is put a reference to this macro variable in the 'to' section. When it compiles, the macro variable will resolve to the list of email addresses (now in quotations), and then execute on that logic.

 

Hope this helps.

 

susana_alves
Calcite | Level 5

Thank you for your help!

tsap
Pyrite | Level 9

You're welcome

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 2004 views
  • 0 likes
  • 2 in conversation