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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 980 views
  • 0 likes
  • 2 in conversation