10 users online | 10 Guests and 0 Registered

Is it possible to use both single and double quotes inside a quoted text string?

Attempting to include examples of both single and double quotation marks inside a quoted string causes problems with early termination of the quoted string, e.g.:

title "Presenting: The 'right' way to use "quotes"!" ;
proc print data = sashelp.class (obs = 1 ) ;
run ;

generates the following in the LOG:

3    title "Presenting: The 'right' way to use "quotes"!" ;
WARNING: The TITLE statement is ambiguous due to invalid options or unquoted text.
NOTE 49-169: The meaning of an identifier after a quoted string may change in a future SAS
             release.  Inserting white space between a quoted string and the succeeding
             identifier is recommended.

the underlined section indication where the system determines the quoted string appears.

Attempting to store the text in a macro variable:

%let titletext = The 'right' way to use "quotes"! ;

title "Presenting: &titletext" ;

proc print data = sashelp.class (obs = 1 ) ;
run ;

generates the same error as the macro variable is resolved for the stored text at Compile Time.

In order to mask the quotation marks, the %BQUOTE Macro Quoting function can be used to remove the special meaning of the characters at Execution Time;

%let titletext = %bquote(The 'right' way to use "quotes"!) ; 

%put _user_ ; 
%put &titletext ;

Using the %put _user_ ; statement renders the value along with the Macro Quoting. Writing the value with the %put &titletext ; statement renders the stored value in the LOG and unquotes the value for printing.The LOG shows the values:

GLOBAL TITLETEXT □The □right□ way to use □quotes□!□

The 'right' way to use "quotes"!

Using the Macro Quoted value within the quoted string

title "Presenting: &titletext" ;

proc print data = sashelp.class (obs = 1 ) ;
run ;

allows for the masked characters to be resolved only for printing, without generating the syntax error at Compile Time:

 Presenting: The 'right' way to use "quotes"!

Obs     Name     Sex    Age    Height    Weight

1    Alfred     M      14      69       112.5
Alan D Rudland
Average rating:0 (0 Votes)

You cannot comment on this entry

Chuck Norris has counted to infinity. Twice.