BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
eagles_dare13
Obsidian | Level 7

I am using below code to send an email:

data _null_;

file sendit email

from="Support@yahoo.com"

to=("xxx@yahoo.com" )

cc=("yyy@yahoo.com")

subject="Report 123"

importance="High"

attach="/home/report.zip";

put "Regards,";
put "Support Team";
put;

My problem is that the To: field needs to read email addresses from a list (dataset). Now I can loop through a dataset ,pick out each email address and send a separate email to each person.

But what i want is to send a single email with all those names in the To field.

How can I do this?

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

Two steps.  Create your list of emails, then set that in a data _null_ and call execute using that loop:

proc sql;
  create table LOOP as
  select  distinct EMAIL
  from    WORK.HAVE;
quit;

data _null_;
  set loop end=last;
  if _n_=1 then do;
    call execute('data _null_;
                    file sendit email
                    from="Support@yahoo.com" to=("'||strip(email)||'"');
  end;
  else do;
    call execute(',"'||strip(email)||'"');
  end;
  if last then do;
    call execute(') cc=("yyy@yahoo.com") subject="Report 123"...

  end;
run;


View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

Two steps.  Create your list of emails, then set that in a data _null_ and call execute using that loop:

proc sql;
  create table LOOP as
  select  distinct EMAIL
  from    WORK.HAVE;
quit;

data _null_;
  set loop end=last;
  if _n_=1 then do;
    call execute('data _null_;
                    file sendit email
                    from="Support@yahoo.com" to=("'||strip(email)||'"');
  end;
  else do;
    call execute(',"'||strip(email)||'"');
  end;
  if last then do;
    call execute(') cc=("yyy@yahoo.com") subject="Report 123"...

  end;
run;


eagles_dare13
Obsidian | Level 7

Thanks. Can  you tell me what is the purpose of this symbol?

||

In sql, we use this to concatenate strings, what is the purpose in this context?

Quentin
Super User

It's the same concatenation operator as you would expect.

For example, you have a string literal 'data _null_; file sendit... ', concatenated to the value of the EMAIL dataset variable, concatenated to another string literal "'" (a single quote mark).

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 7212 views
  • 6 likes
  • 3 in conversation