NVALID Function

Checks the validity of a character string for use as a SAS variable name.

Category:Character
Restrictions:This function is assigned an I18N Level 2 status, and is designed for use with SBCS, DBCS, and MBCS (UTF8). For more information, see Internationalization Compatibility.
This function is not valid on the CAS server.

Syntax

NVALID(string <, validvarname>)

Required Argument

string

specifies a character constant, variable, or expression that is checked to determine whether its value can be used as a SAS variable name.

Note: Trailing blanks are ignored.
TipEnclose a literal string of characters in quotation marks.

Optional Argument

validvarname

is a character constant, variable, or expression that specifies one of the following values:

V7

determines that string is a valid SAS variable name when all three of the following are true:

  • string 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

ANY

determines that string is a valid SAS variable name if it contains 32 or fewer characters of any type, including blanks.

NLITERAL

determines that string is a valid SAS variable name if it is in the form of a SAS name literal ('name'N) or if it is a valid SAS variable name when VALIDVARNAME=V7.

SeeV7 above in this same list.
DefaultIf no value is specified, the NVALID function determines that string is a valid SAS variable name based on the value of the SAS system option VALIDVARNAME=.

Details

The NVALID function checks the value of string to determine whether it can be used as a SAS variable name.
The NVALID function returns a value of 1 or 0.
Condition
Returned Value
string can be used as a SAS variable name
1
string cannot be used as a SAS variable name
0

Example

This example determines the validity of specified strings as SAS variable names. The value that is returned by the NVALID function varies with the validvarname argument. The value of 1 is returned when the string is determined to be a valid SAS variable name under the rules for the specified validvarname argument. Otherwise, the value of 0 is returned.
options validvarname=v7 ls=64;
data string;
   input string $char40.;
   v7=nvalid(string, 'v7');
   any=nvalid(string, 'any');
   nliteral=nvalid(string, 'nliteral');
   default=nvalid(string);
   datalines;
Tooooooooooooooooooooooooooo Long
OK
Very_Long_But_Still_OK_for_V7
1st_char_is_a_digit
Embedded blank
!@#$%^&*
"Very Loooong N-Literal with """N
'No closing quotation mark
;
          
proc print noobs;
title1 'NLITERAL and Validvarname Arguments Determine';
title2 'Invalid (0) and Valid (1) SAS Variable Names';
run;
Output from Determining the Validity of SAS Variable Names with NLITERAL
Output from Determining the Validity of SAS Variable Names with NLITERAL

See Also

System Options:
VALIDVARNAME= System Option in SAS Viya System Options: Reference
Last updated: March 16, 2017