BookmarkSubscribeRSS Feed
pchappus
Obsidian | Level 7

Can somebody much smarter than me help me understand what %QUOTE does? The online documentation says it "masks" a string. Does that mean it ignores things like a quoted string?

 

Here is the line of code I'm trying to understand.

 

%IF &strInToLine NE %QUOTE(NONE) %THEN %DO;

 

I've seen examples where the %QUOTE is used around the macro variable but not around a text like NONE.

 

Thanks

6 REPLIES 6
PaigeMiller
Diamond | Level 26

%QUOTE should be used on macro variables if they could possibly contain special characters that could cause confusion on the part of the macro processor. The documentation for %QUOTE indicates which characters are considered special  characters.

 

%QUOTE would never be used on just plain text, for example %QUOTE(NONE) is not appropriate use of %QUOTE.

--
Paige Miller
pchappus
Obsidian | Level 7

Okay, I think I might need it around the marco variable then. 

 

I'm trying to read in a text file that has a quoted email address like the following:

 

"XXXX@gmail.com"

 

When I use the code to send this, it is looking like it is stripping the quotes and causing it to not send the email.

 

If I instead put the following in the text file that gets read in with the email address, it works:

 

"XXXX@gmail.com" "XXXX@gmail.com"

 

For some reason, when I have two quoted email address I don't have a problem.

 

Thanks,

pchappus
Obsidian | Level 7

The issue appears to be maybe in the PROC import. Trying to find out if PROC import strips the quotes from a quoted string.

 

Paul

Tom
Super User Tom
Super User

@pchappus wrote:

The issue appears to be maybe in the PROC import. Trying to find out if PROC import strips the quotes from a quoted string.

 

Paul


Are you reading from a CSV file (delimited text file)?  In a CSV file quotes around values are considered optional and are removed. 

That is how you can have values in your file that contain the comma (or whatever delimiter you are using) and still be able to parse the lines. If your values contain actual quotes then the value should be quoted and any embedded quotes (of the same type as the values is enclosed in) need to doubled up.  For SAS you can use either single or double quote characters on the outside.

So for example a record that had NAME='Smith, Fred' and email='fred.smith@company.org' and nickname='"Rock"' would be written to a CSV file like this:

Name,Email,Nickname
"Smith, Fred",fred.smith@company.org,"""Rock"""

If you do have a CSV file and you want to preserve the quotes around a particular columns values you can use the ~ modifier on the INPUT statement.

data test ;
 length name email nickname $50 ;
 infile cards dsd truncover firstobs=2;
 input name email nickname ~;
cards;
Name,Email,Nickname
"Smith, Fred",fred.smith@company.org,"Rock"
;;;;
Obs       name                email             nickname

 1     Smith, Fred    fred.smith@company.org     "Rock"
Tom
Super User Tom
Super User

Note that to the macro processor quotes are part of the value.  To the macro processor everything is just text so there is no need to add quotes around stings to help the parser figure out that the word is not meant as a number or variable name or keyword.

 

So if your macro variable contains XXX and you compare it to "XXX" it will not match since one starts with X and the other with a double quote character.

 

%let email = fred.smith@company.org ;
...
%if &email = fred.smith@company.org %then %do;
%put Sending email to Fred ;
...
%end;
Ksharp
Super User

%QUOTE is obsolete . It can't mask single/double quote , use %bquote() instead.

For now ,generally consider these three macro mask function  %BQUOTE() %NRBQUOTE() %SUPERQ()

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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