QUOTE Function

Adds double quotation marks to a character value.

Category: Character
Restriction: I18N Level 2 functions are designed for use with SBCS, DBCS, and MBCS (UTF8).

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 SAS statements produce these results.
SAS Statement
Result
x='A"B';
y=quote(x);
put y;
 
"A""B"
x='A''B';
y=quote(x);
put y;
 
"A'B"
x='Paul''s';
y=quote(x);
put y;
 
"Paul's"
x='Catering Service Center      ';
y=quote(x);
put y;
"Catering Service Center      "
x='Paul''s Catering Service          ';
y=quote(trim(x));
puty;
"Paul's Catering Service:
x=quote('abc');
put x=;
"abc"
x=quote('abc',"'");
put x=;
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'