Nesting Quotes in Strings
From sasCommunity
Contents |
[edit] Before Double Quotes
Once upon a time, double quotes were not a significant part of the programming world. Some keyboards and/or keypunch machines did not provide for them. And there was a SAS system option (DQUOTE) to support them in SAS code. So, as in many other programming languages, nesting a single quote, aka apostrophe, within a character string was a special challenge if the string itself was enclosed in single quotes.
[edit] Promoting Quotes
To resolve this issue, the technique of using two quotes to represent a single quote character was used. The term "promoting quotes" frequently is applied to this practice. However, in most cases, using double quotes is a simpler approach.
[edit] Examples
Here are two examples of placing an apostrophe within SAS title text. Both produce the correct result.
title 'SAS User''s Blog';
title "SAS User's Blog";
[edit] Other Techniques
The SAS function QUOTE may be useful when creating a variable or expression that must contain a literal with surrounding double quotes as part of the value. The DEQUOTE function can be helpful when removing the surrounding quotes from such a character value.
Although not used in traditional SAS code, other languages support escape sequences to represent characters that may be ambiguous. For example, the character sequence \' may represent an apostrophe within a single-quoted literal, where the backslash is the escape character.
