I am using SAS metadata to create a SAS macro called &SASAdmin....This macro will be used to store all the sas admin email address so I can send an email to all the SASAdmins. I want to dynamically set the value so I don't have to constantly manage the "TO" email address if an employee leaves or a new employee is hired. This code works if in the TO: line is hard coded such as
' 'email1@test.org "email2@test.org" '
but does not work if i put
TO "&SASAdmin"
Code is below:
options emailsys=smtp emailhost=smtp.test.org emailport=25;
FILENAME output EMAIL
SUBJECT= "SAS PROGRAM ERROR"
FROM= "test@test.org"
TO= "&SASAdmin"
importance='high'
CT= "text/html" /* Required for HTML output*/;
ODS HTML BODY=output STYLE=minimal;
title "<div align='Center' style ='font-size:12pt'> SAS PROGRAM ERROR TEST</div>";
footnote "<div style = 'font-size:10pt'> This E-mail is auto-generated from SAS on &sysday, &sysdate9.</div>";
footnote2 "<div style = 'font-size:10pt'> on the &sysscp system using Release &sysver </div>";
proc report data=enviromentspecs;
column programowner programpath lastruntime errortext;
define programowner / display;
define programprath / display;
define lastruntime / display;
define errortext / display;
label
programowner = 'Program Owner'
programpath = 'Program Path'
lastruntime = 'Program Last Run Time'
errortext = 'Program Error Text';
run;
errors:
ERROR 23-2: Invalid option name SASAdmin.
ERROR: Error in the FILENAME statement.
ERROR: No logical assign for filename OUTPUT.
ERROR: No body file. HTML output will not be created.
When the macro variable that contains
"test1@test.org""test2@test.org""test3@test.org"
is resolved in this
TO= "&SASAdmin"
you get
TO= ""test1@test.org""test2@test.org""test3@test.org""
This can't work. A list of email recipients needs to be enclosed in parentheses (see the documentation), so you should use
TO=(&SASAdmin)
How did you create the macro variable &sasadmin? Please show that piece of code.
Replicated code below:
data temp;
infile DATALINES;
length emailaddr $20.;
input keyid$ emailaddr$ displayname$;
CARDS;
1 test1@test.org test1
2 test2@test.org test2
3 test3@test.org test3
;
run;
data temp1; set temp;
first = '"';
second = '"';
Email = catx('',first,emailAddr,second);
Email1 = compress(email);
TextList = 'NULL';
Team = 'SAS';
LastUpdateDt = datetime();
format LastUpdateDt datetime22.3;
run;
data temp2;
length emaillist $10000.;
do until (last.team);
set temp1;
by team notsorted;
emaillist=cats(emaillist,'',Email1);
end;
drop Email1 emailaddr first second email displayname keyid ;
run;
data _null_; set work.temp2;
call symput ('SASAdmin1',emaillist);
run;
%put sas admins are &SASAdmin1;
LOG:
%put sas admins are &SASAdmin1;
sas admins are "test1@test.org""test2@test.org""test3@test.org"
You create sasadmin1, but try to use sysadmin.
The code above is replicated (I changed the sasadmin to sasadmin1) but in the original code use SASADMIN and create SASADMIN. I did this to de-identify the actual email address of the recipients of the email but still be able to provide you with sample code that matches the original.
When the macro variable that contains
"test1@test.org""test2@test.org""test3@test.org"
is resolved in this
TO= "&SASAdmin"
you get
TO= ""test1@test.org""test2@test.org""test3@test.org""
This can't work. A list of email recipients needs to be enclosed in parentheses (see the documentation), so you should use
TO=(&SASAdmin)
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.