BookmarkSubscribeRSS Feed
horim
Calcite | Level 5

Hi. 

I have a question when do I have to use double quotation marks in where statement.

horim_0-1692506539084.png

In this problem, it says that I have to use single quotation marks.

horim_1-1692506693453.png

But in this problem, I can use double quotation marks.

What is the difference between both situations?

Thank you !

1 REPLY 1
Tom
Super User Tom
Super User

SAS itself does not care if you use single quote characters (also called apostrophes)  or double quote characters on the outside to create string literals.

 

And it does not matter whether the string literals appear in a WHERE clause or any other place where a string literal can be used.

 

They suggested using single quotes in the first example because of the % characters in the sting.  The % and & characters are important to the MACRO PROCESSOR.   The macro processor is a pre-processor that analyses the code and can be used to generate different SAS code based on the macro statements, macro variable references and macro call it sees in the text of the code.  The macro processor uses % as the trigger to look for a macro statement, or macro function call or a macro call.  It uses & as the trigger to start the evaluation of macro variable references.

 

But the macro processor will ignore string literals that are bounded by single quotes.  So when you use single quotes to enclose the string literal the macro processor will NOT see the string %preserve as an attempt to call a macro named preserve.

 

The second example does not have that problem because there is no way that the macro processor will interpret that % sign as the start of macro code since it is immediately followed by the quote. So in the second situation you can use either double quote characters, "YOSE%", or single quote characters, 'YOSE%', since there is no need to hide that string from the macro processor.

sas-innovate-2024.png

 

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

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
  • 1 reply
  • 161 views
  • 0 likes
  • 2 in conversation