Below is a part of a macro I am using for email. The problem arises when I have email containing single quotations like john o'brien@gmail.com in which case I get an error. Even though I am using %nrquote function for masking, I am getting this error.
filename Mailbox
542 EMAIL
543 FROM = maverick@gmail.com
544 TO = %nrquote(&personsemail)
548 SUBJECT = "I am having an issue"
Would highly appreciate the help.
Thanks
You may want %nrbquote
I want the email to be double quoted instead of single quote.
Eg. TO="john'obrien@gmail.com"
the issue is occurring because by default the email is single quoted when resolved. ie. 'john'o'brien'@gmail.com'
Should be easier to switch to %SUPERQ. Note that %SUPERQ does not want to see the ampersand:
TO = "%superq(personsemail)"
Of course, that assumes that the rest of the syntax is correct ... this is just to get rid of the macro quoting issue. I mention that because it's difficult to determine from your post what SAS statements you are hoping to generate.
Good luck.
What is the exact SAS error received? My attempt resolved the quote / double-quote correctly and the EMAIL was generated as expected. Suggest you post the exact SAS code piece in its entirety and the SASLOG error diagnostics.
Hi SBB,
Thanks for the reply. Below is the code and the log. Basically I need to double quote emails in the TO= statement. Believe that would solve the issue
data test;
email="testing o'brien@gmail.com";
run;
proc sql noprint;
select email into : email from test;
quit;
options symbolgen mprint mlogic;
%put email=%nrbquote(&email.);
%macro mail;
filename MailBox
FROM = 'testing@gmail.com>'
TO = %nrbquote(&email.)
SUBJECT = "My Email Is Not Working";
data _null_;
file MailBox;
put "Hello" ;
put " " ;
run;
%mend mail;
%mail;
LOG:
94 options symbolgen mprint mlogic;
95
96 %put email=%nrbquote(&email.);
SYMBOLGEN: Macro variable EMAIL resolves to testing o'brien@gmail.com
email=testing o'brien@gmail.com
97 %macro mail;
98
99 filename MailBox
100 EMAIL
101 FROM = 'testing@gmail.com>'
102 TO = %nrbquote(&email.)
103 SUBJECT = "My Email Is Not Working";
104 data _null_;
105 file MailBox;
106 put "Hello" ;
107 put " " ;
108 run;
109
110 %mend mail;
111
112 %mail;
MLOGIC(MAIL): Beginning execution.
SYMBOLGEN: Macro variable EMAIL resolves to testing o'brien@gmail.com
NOTE: Line generated by the macro function "NRBQUOTE".
1 testing o'brien@gmail.com
-----
23
MPRINT(MAIL): filename MailBox EMAIL FROM = 'testing@gmail.com>' TO = testing
o'brien@gmail.com SUBJECT = "My Email Is Not Working";
ERROR: Error in the FILENAME statement.
MPRINT(MAIL): data _null_;
MPRINT(MAIL): file MailBox;
MPRINT(MAIL): put "Hello" ;
MPRINT(MAIL): put " " ;
MPRINT(MAIL): run;
ERROR 23-2: Invalid option name brien.
NOTE: The file MAILBOX is:
Filename=C:\Users\212441413\mailbox.dat,
RECFM=V,LRECL=256,File Size (bytes)=0,
Last Modified=26Mar2015:00:35:04,
Create Time=26Mar2015:00:14:58
The final syntax must have double-quotes surrounding your EMAIL address, whether you generate that in the PROC SQL or hardcode it in the TO= ( .... ) parameter surround your macro variable resolved EMAIL address(es). The error is due to the TO= lacking double-quotes surrounding each address and if you intend to code multiple addresses, the entire TO=(....) must be surrounded with parentheses.
I think you will be better off using e-mail directives. You probably won't need any messy macro bits. Have a look at the examples in the link.
How are you populating the macro variable with the email address?
You should not need to use macro quoting, just quote the address. Use the QUOTE() or CATQ() function to make sure that quotes are generated properly.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.