Previous Page | Next Page

Functions and CALL Routines

NLITERAL Function



Converts a character string that you specify to a SAS name literal.
Category: Character
Restriction: I18N Level 2

Syntax
Arguments
Details
Length of Returned Variable
The Basics
Examples
See Also

Syntax

NLITERAL(string)


Arguments

string

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

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

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:

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.


Examples

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

            Strings Converted to N-Literals or Returned Unchanged            1

          Obs    string                   result

           1     abc_123                  abc_123                  
           2     This and That            "This and That"N         
           3     cats & dogs              'cats & dogs'N           
           4     Company's profits (%)    'Company''s profits (%)'N
           5     "Double Quotes"          '"Double Quotes"'N       
           6     'Single Quotes'          "'Single Quotes'"N       

See Also

Functions:

COMPARE Function

DEQUOTE Function

NVALID Function

System Option:

VALIDVARNAME= System Option

Rules for Words and Names in the SAS Language in SAS Language Reference: Concepts

Previous Page | Next Page | Top of Page