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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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
  • 3 replies
  • 1508 views
  • 0 likes
  • 2 in conversation