NLITERAL Function

Converts a character string that you specify to a SAS name literal.

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

Syntax

NLITERAL(string)

Required Argument

string

specifies a character constant, variable, or expression that is to be converted to a SAS name literal.

Restriction If the string is a valid SAS variable name, it is not changed.
Tip Enclose a literal string of characters in quotation marks.

Details

Length of Returned Variable

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

The Basics

String will be converted to a name literal, unless it qualifies under the default rules for a SAS variable name. These default rules are in effect when the SAS system option VALIDVARNAME=V7:
  • It begins with an English letter or an underscore.
  • All subsequent characters are English letters, underscores, or digits.
  • The length is 32 or fewer alphanumeric characters.
String qualifies as a SAS variable name, when all of these rules are true.
The NLITERAL function encloses the value of string in single or double quotation marks, based on the contents of string.
Value in string
Result
an ampersand (&)
enclosed in single quotation marks
a percent sign (%)
enclosed in single quotation marks
more double quotation marks than single quotation marks
enclosed in single quotation marks
none of the above
enclosed in double quotation marks
If insufficient space is available for the resulting n-literal, NLITERAL returns a blank string, prints an error message, and sets _ERROR_ to 1.

Example

This example demonstrates multiple uses of NLITERAL.
data test;
   input string $32.;
   length result $ 67;
   result = nliteral(string);
   datalines;
abc_123
This and That
cats & dogs
Company's profits (%)
"Double Quotes"
'Single Quotes'
;
proc print;
title 'Strings Converted to N-Literals or Returned Unchanged';
run;
Converting Strings to Name Literals with NLITERAL
Converting Strings to Name Literals with NLITERAL

See Also

System Options:
VALIDVARNAME= System Option in SAS System Options: Reference
Other References:
Words in the SAS Language in SAS Language Reference: Concepts