NVALID Function


NVALID Function

Checks a character string for validity for use as a SAS variable name in a SAS statement

Category: Character

Syntax

NVALID ( string < ,validvarname >)

Arguments

string

  • specifies a character constant, variable, or expression which will be checked to determine if it can be used as a SAS variable name in a SAS statement.

  • Note: Trailing blanks are ignored.

  • Tip: Enclose a literal string of characters in quotation marks.

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:

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

    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.

    See: V7 above in this same list.

  • Default: If 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 string to determine if it can be used as a SAS variable name in a SAS statement.

The NVALID function returns a value or 1 or 0.

If this condition exists

NVALID returns a value of

string can be used as a SAS variable name in a SAS statement

1

string cannot be used as a SAS variable name in a SAS statement

Examples

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 4.29: Determining the Validity of SAS Variable Names with NLITERAL
start example
 NLITERAL and Validvarname Arguments Determine           1          Invalid (0) and Valid (1) SAS Variable Names  string                            v7  any  nliteral  default  Tooooooooooooooooooooooooooo Long  0   0       0        0                                     0   0       0        0  OK                                 1   1       1        1  Very_Long_But_Still_OK_for_V7      1   1       1        1  1st_char_is_a_digit                0   1       1        0  Embedded blank                     0   1       1        0  !@#$%^&*                           0   1       1        0  "Very Loooong N-Literal with """N  0   0       1        0  'No closing quotation mark         0   1       0        0 
end example
 

See Also

Functions:

  • 'COMPARE Function' on page 445

  • 'NLITERAL Function' on page 662

System Option:

  • 'VALIDVARNAME= System Option' on page 1624

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




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net