QUOTE Function
Adds double quotation marks to a character value.
| Categories: | Character |
| CAS | |
| Restriction: | This function is assigned an I18N Level 2 status, and is designed for use with SBCS, DBCS, and MBCS (UTF8). For more information, see Internationalization Compatibility. |
| Note: | This function supports the VARCHAR type. |
Syntax
Required Arguments
argument-1
specifies a character constant, variable, or expression.
argument-2
specifies a quoting character, which is a single or double quotation mark. Other characters are ignored and the double quotation mark is used. The double quotation mark is the default.
Details
Length of Returned Variable
In a DATA step, if the
QUOTE function returns a value to a variable that has not previously
been assigned a length, then that variable is given a length of 200
bytes.
The Basics
The QUOTE function adds
double quotation marks, the default character, to a character value.
If double quotation marks are found within the argument, they are
doubled in the output.
The length of the receiving
variable must be long enough to contain the argument (including trailing
blanks), leading and trailing quotation marks, and any embedded quotation
marks that are doubled. For example, if the argument is ABC followed
by three trailing blanks, then the receiving variable must have a
length of at least eight to hold “ABC###”. (The character
# represents a blank space.) If the receiving field is not long enough,
the QUOTE function returns a blank string and writes an invalid argument
note to the log.
Example
The following examples
demonstrate the functionality of the QUOTE function:
|
SAS Statement
|
Result
|
|---|---|
data _null_; x='A"B'; a=quote(x); put a=; run; |
a="A""B" |
data _null_; x='A''B'; b=quote(x); put b=; run; |
b="A'B" |
data _null_; x='Paul''s'; c=quote(x); put c=; run; |
c="Paul's" |
data _null_; x='Paul''s Catering Service '; d=quote(trim(x)); put d=; run; |
d="Paul's Catering Service" |
data _null_;
x='Catering Service Center ';
e=quote(trim(x));
put e=;
run; |
e="Catering Service Center" |
data _null_; x='Catering Service Center '; f=quote(x); put f=; run; |
f="Catering Service Center " |
data _null_; x='Catering Service Center '; g=quote(x); put g=; run; |
g="Catering Service Center " |
data _null_; x='Catering Service Center '; h=quote(x); put h=; run; |
h="Catering Service Center " |
data_null;
x=quote('abc');
put x=;
run; |
"abc" |
data_null;
x=quote('abc',"'");
put x=;
run;Note: The second argument contains
a single quotation mark. In order to be passed to the function in
the DATA step, the argument is specified in the DATA step as double
quotation mark, single quotation mark, double quotation mark. The
argument could have also been specified as four single quotation marks
(that is, a quoted string that uses single quotation marks). The quoted
value is an escaped single quotation mark represented as two single
quotation marks.
|
'abc' |
Copyright © SAS Institute Inc. All Rights Reserved.
Last updated: March 16, 2017