Functions and CALL Routines |
Converts a character string that you specify to a SAS name literal.
-
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. |
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.
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.
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
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.