Converts a character string that you specify to a SAS name literal (n-literal)
Category: Character
NLITERAL ( string )
string
specifies a character constant, variable, or expression that is to be converted to a SAS name literal (n-literal).
Tip: Enclose a literal string of characters in quotation marks.
Restriction: If the string is a valid SAS variable name, by default, it is not converted to an n-literal.
If the NLITERAL function returns a value to a variable that has not yet been assigned a length, by default the variable is assigned a length of 200.
The NLITERAL function converts string to a SAS name literal (n-literal). String will be converted to an n-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 , therefore, qualifies as a SAS variable name, when all of these are true.
CAUTION:
If insufficient space is available for the resulting n-literal, NLITERAL returns a blank string, prints an error message, and sets _ERROR_ to 1.
The NLITERAL function encloses the value of string in single or double quotation marks, based on the contents of string .
If string contains | NLITERAL encloses the result in |
---|---|
an ampersand (&) | single quotation marks |
a percent sign (%) | single quotation marks |
more double quotation marks than single quotation marks | single quotation marks |
none of the above | double quotation marks |
This example demonstrates multiple uses of NLITERAL.
data test; input string .; 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;
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
Functions:
'COMPARE Function' on page 445
'DEQUOTE Function' on page 491
'NVALID Function' on page 688
System Option:
'VALIDVARNAME= System Option' on page 1624
'Rules for Words and Names in the SAS Language' in SAS Language Reference: Concepts