DATA Step, Macro, Functions and more

Email Macro NRQUOTE Issue

Reply
Contributor
Posts: 64

Email Macro NRQUOTE Issue

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

Super User
Posts: 10,466

Re: Email Macro NRQUOTE Issue

You may want %nrbquote

Contributor
Posts: 64

Re: Email Macro NRQUOTE Issue

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'

Super User
Posts: 5,071

Re: Email Macro NRQUOTE Issue

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.

Super Contributor
Super Contributor
Posts: 3,174

Re: Email Macro NRQUOTE Issue

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.

Contributor
Posts: 64

Re: Email Macro NRQUOTE Issue

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

Super Contributor
Super Contributor
Posts: 3,174

Re: Email Macro NRQUOTE Issue

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.

Respected Advisor
Posts: 3,777

Re: Email Macro NRQUOTE Issue

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

Super User
Super User
Posts: 6,497

Re: Email Macro NRQUOTE Issue

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.

Ask a Question
Discussion stats
  • 8 replies
  • 307 views
  • 0 likes
  • 6 in conversation