DEQUOTE Function

Removes matching quotation marks from a character string that begins with a quotation mark, and deletes all characters to the right of the closing quotation mark.

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

Syntax

DEQUOTE(string)

Required Argument

string

specifies a character constant, variable, or expression.

Details

Length of Returned Variable

In a DATA step, if the DEQUOTE function returns a value to a variable that has not been previously assigned a length, then that variable is given the length of the argument.

The Basics

The value that is returned by the DEQUOTE function is determined as follows:
  • If the first character of string is not a single or double quotation mark, DEQUOTE returns string unchanged.
  • If the first two characters of string are both single quotation marks or both double quotation marks, and the third character is not the same type of quotation mark, then DEQUOTE returns a result with a length of zero.
  • If the first character of string is a single quotation mark, the DEQUOTE function removes that single quotation mark from the result. DEQUOTE then scans string from left to right, looking for more single quotation marks. Each pair of consecutive, single quotation marks is reduced to one single quotation mark. The first single quotation mark that does not have an ending quotation mark in string is removed and all characters to the right of that quotation mark are also removed.
  • If the first character of string is a double quotation mark, the DEQUOTE function removes that double quotation mark from the result. DEQUOTE then scans string from left to right, looking for more double quotation marks. Each pair of consecutive, double quotation marks is reduced to one double quotation mark. The first double quotation mark that does not have an ending quotation mark in string is removed and all characters to the right of that quotation mark are also removed.
Note: If string is a constant enclosed by quotation marks, those quotation marks are not part of the value of string. Therefore, you do not need to use DEQUOTE to remove the quotation marks that denote a constant.

Example

This example demonstrates the use of DEQUOTE within a DATA step.
data test;
   input string $60.;
   result = dequote(string);
   datalines;
No quotation marks, no change
No "leading" quotation marks, no change
"Matching double quotation marks are removed"
'Matching single quotation marks are removed'
"Paired ""quotation marks"" are reduced"
'Paired '' quotation marks '' are reduced'
"Single 'quotation marks' inside '' double'' quotation marks are unchanged"
'Double "quotation marks" inside ""single"" quotation marks are unchanged'
"No matching quotation mark, no problem
Don't remove this apostrophe
"Text after the matching quotation mark" is "deleted"
;
proc print noobs;
title 'Input Strings and Output Results from DEQUOTE';
run;
Removing Matching Quotation Marks with the DEQUOTE Function
Removing Matching Quotation Marks with the DEQUOTE Function