Date: Thu, 14 Aug 2008 10:13:39 -0400
Reply-To: Dave Scocca <dave@SCOCCA.ORG>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Dave Scocca <dave@SCOCCA.ORG>
Subject: Re: Escaping quotes in SCL
Content-Type: text/plain; charset=us-ascii; format=flowed
--On 8/14/2008 6:47 AM -0700 Adam wrote:
>> A single quote constant can be specified as "'" double quote
>> surrounding single quote or '''' two single quotes withing a single
>> quoted string, to name two.
> Thanks for this. You've made me go back and try again with my original
> index() attempt.
> Well, I've ended up with this, which appears to work:
> if index(txtDesc.text,'"') or index(txtDesc.text,"'") then ... /*
> report error to user */
Another thing to do--that saves a lot of worrying about quotation marks--is
to use the QUOTE() function. So instead of building a where clause like:
myWhereClause = '(where=(' || myVarName || '="' || myValue || '"))' ;
(in which you have to keep track of the double quotes inside the single
quotes, and hope that MYVALUE doesn't have any double quotes in it), you
myWhereClause = '(where=(' || myVarName || '=' || quote(myValue) || '))' ;
or (best of all)
myWhereOption = catS('(where=(', myVarName, '=', quote(myValue), '))') ;
and let SAS take care of the quoting (and SAS will properly handle the case
where MYVALUE contains double quotes, e.g.:
549 data _null_ ;
550 length x $30 ;
551 x=quote('He said "Hi" to me') ;
552 put x= ;
553 run ;
x="He said ""Hi"" to me"
NOTE: DATA statement used (Total process time):
where internal double quotes are repeated.).
So if the field could legitimately have a quote in it, QUOTE() makes it
easier to handle.
For reference: the characters that are verboten in a Windows filename are:
/ \ * : ? " < > |
(single quotes/apostrophes are OK, double quotes are not)