BookmarkSubscribeRSS Feed
sasmaverick
Obsidian | Level 7

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

8 REPLIES 8
ballardw
Super User

You may want %nrbquote

sasmaverick
Obsidian | Level 7

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'

Astounding
PROC Star

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.

sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10

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.

sasmaverick
Obsidian | Level 7

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

EMAIL

    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

sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10

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.

data_null__
Jade | Level 19

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.

Specifying E-mail Directives in the PUT Statement

Tom
Super User Tom
Super User

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 8 replies
  • 1064 views
  • 0 likes
  • 6 in conversation