DATA Step, Macro, Functions and more

How do I SAS email to different addresses depending on criteria ?

Reply
Occasional Contributor
Posts: 9

How do I SAS email to different addresses depending on criteria ?

Hi

 

I am using SAS EG / Base SAS &  trying to send emails to different recipients depending on certain criteria,  I have this bock of code within the program.

 

if (&Customer_Segment='R' or 'U') then do;
file sendit email
from = "XXX@company.co.nz"
to = ("YYY@company.co.nz") 
subject= "TEST email 1" ;end;


if (&Customer_Segment='S') then do;
file sendit email
from = "XXX@company.co.nz"
to = ("ZZZ@company.co.nz") 
subject= "TEST email 2" ;end;


if (&Customer_Segment='C' or 'P') then do;
file sendit email
from = "XXX@company.co.nz"
to = ("QQQ@company.co.nz") 
subject= "TEST email 3" ;end;

 

 

Customer_Segment is defined further down in the program for each email to be sent , e.g.

 

%S_Letter (Letter_No='L02',
Customer_No='1234567890',
Account_No='nnnnnnnnnnnnnnnn001',
Customer_Segment='R',		 
Staff_No=222222,
Manager_Status='Vacant',   
Customer_Name='Donald Duck',  ;		



%S_Letter (Letter_No='L05',
Customer_No='1234567890',
Account_No='nnnnnnnnnnnnnnnn001',
Customer_Segment='S',		 
Staff_No=222222,
Manager_Status='Managed',   
Customer_Name='Mickey Mouse',  ;

 

 

My problem is that no matter what the Customer_Segment is it always sends every email to the last  address etc. as if no other variations have been coded .... so in the above example the letter to Donald Duck - Customer Segment 'R'  ... would get sent to QQQ@company.co.nz with subject line 'TEST email 3' .... instead of YYY@company.co.nz with subject line 'TEST email 1'

 

any help much appreciated !

Super User
Posts: 23,323

Re: How do I SAS email to different addresses depending on criteria ?

Make a table with that information instead, even if you're creating it from a CARDS statement. Then build your recipient list from that table and feed that to your email program. 

 

I don't think file statements are conditional though, so you may need to make those macro %IF/%THEN or use a different method to create the file reference. There may be a function for that...

Ask a Question
Discussion stats
  • 1 reply
  • 82 views
  • 0 likes
  • 2 in conversation