SAS Variable Attributes


A SAS variable has the attributes that are listed in the following table:

Table 5.1: Variable Attributes

Variable Attribute

Possible Values

Default Value

Name

Any valid SAS name. See Chapter 3, 'Rules for Words and Names in the SAS Language,' on page 15.

None

Type [1]

Numeric and character

Numeric

Length [1]

2 to 8 bytes [2]

1 to 32,767 bytes for character

8 bytes for numeric and

character

Format

See 'Formats and Informats' on page 27.

BEST12. for numeric, $ w. for character

Informat

See 'Formats and Informats' on page 27.

w.d for numeric, $ w. for character

Label

Up to 256 characters

None

Position in observation

1- n

None

Index type

NONE, SIMPLE, COMPOSITE, or BOTH

None

[1] If they are not explicitly defined, a variable's type and length are implicitly defined by its first occurrence in a DATA step.

[2] The minimumlength is 2 bytesin someoperating environments,3 bytesin others. See the SAS documentation for your operating environment.

Note: Starting with SAS 9.1, the maximum number of variables can be greater than 32,767. The maximum number is dependent on your environment and the file's attributes.

You can use the CONTENTS procedure, or the functions that are named in the following definitions, to obtain information about a variable's attributes:

name

  • identifies a variable. A variable name must conform to SAS naming rules. A SAS name can be up to 32 characters long. The first character must be a letter (A, B, C, ,Z)orunderscore (_). Subsequent characters can be letters , digits (0 to 9), or underscores. Note that blanks are not allowed. Mixed case variables are allowed. See Chapter 3, 'Rules for Words and Names in the SAS Language,' on page 15 for more details on mixed case variables.

    The names _N_, _ERROR_, _FILE_, _INFILE_, _MSG_, _IORC_, and _CMD_ are reserved for the variables that are generated automatically for a DATA step. Note that SAS products use variable names that start and end with an underscore; it is recommended that you do not use names that start and end with an underscore in your own applications. See 'Automatic Variables' on page 85 for more information.

    To determine the value of this attribute, use the VNAME or VARNAME function.

    Note: The rules for variable names that are described in this section apply when the VALIDVARNAME= system option is set to VALIDVARNAME=V7, which is the default setting. Other rules apply when this option is set differently. See Chapter 3, 'Rules for Words and Names in the SAS Language,' on page 15 for more information.

type

  • identifies a variable as numeric or character. Within a DATA step, a variable is assumed to be numeric unless character is indicated. Numeric values represent numbers, can be read in a variety of ways, and are stored in floating-point format. Character values can contain letters, numbers , and special characters and can be from 1 to 32,767 characters long.

    To determine the value of this attribute, use the VTYPE or VARTYPE function.

length

  • refers to the number of bytes used to store each of the variable's values in a SAS data set. You can use a LENGTH statement to set the length of both numeric and character variables. Variable lengths specified in a LENGTH statement affect the length of numeric variables only in the output data set; during processing, all numeric variables have a length of 8. Lengths of character variables specified in a LENGTH statement affect both the length during processing and the length in the output data set.

    In an INPUT statement, you can assign a length other than the default length to character variables. You can also assign a length to a variable in the ATTRIB statement. A variable that appears for the first time on the left side of an assignment statement has the same length as the expression on the right side of the assignment statement.

    To determine the value of this attribute, use the VLENGTH or VARLEN function.

format

  • refers to the instructions that SAS uses when printing variable values. If no format is specified, the default format is BEST12. for a numeric variable, and $ w . for a character variable. You can assign SAS formats to a variable in the FORMAT or ATTRIB statement. You can use the FORMAT procedure to create your own format for a variable.

    To determine the value of this attribute, use the VFORMAT or VARFMT function.

informat

  • refers to the instructions that SAS uses when reading data values. If no informat is specified, the default informat is w.d for a numeric variable, and $ w . for a character variable. You can assign SAS informats to a variable in the INFORMAT or ATTRIB statement. You can use the FORMAT procedure to create your own informat for a variable.

    To determine the value of this attribute, use the VINFORMAT or VARINFMT function.

label

  • refers to a descriptive label up to 256 characters long. A variable label, which can be printed by some SAS procedures, is useful in report writing. You can assign a label to a variable with a LABEL or ATTRIB statement.

    To determine the value of this attribute, use the VLABEL or VARLABEL function.

position in observation

  • is determined by the order in which the variables are defined in the DATA step. You can find the position of a variable in the observations of a SAS data set by using the CONTENTS procedure. This attribute is generally not important within the DATA step except in variable lists, such as the following:

     var rent-phone; 

    See 'SAS Variable Lists' on page 86 for more information.

    The positions of variables in a SAS data set affect the order in which they appear in the output of SAS procedures, unless you control the order within your program, for example, with a VAR statement.

    To determine the value of this attribute, use the VARNUM function.

index type

  • indicates whether the variable is part of an index for the data set. See 'Understanding SAS Indexes' on page 518 for more information.

  • To determine the value of this attribute, use the OUT= option with the CONTENTS procedure to create an output data set. The IDXUSAGE variable in the output data set contains one of the following values for each variable:

Table 5.2: Index Type Attribute Values

Value

Definition

NONE

The variable is not indexed.

SIMPLE

The variable is part of a simple index.

COMPOSITE

The variable is part of one or more composite indexes.

BOTH

The variable is part of both simple and composite indexes.




SAS 9.1 Language Reference. Concepts
SAS 9.1 Language Reference Concepts
ISBN: 1590471989
EAN: 2147483647
Year: 2004
Pages: 255

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