Chapter Contents

Previous

Next

Variable Attributes

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

Variable Attributes
Variable Attribute Possible Values Default Value
Name Any valid SAS name. See Rules for Words and Names. None
Type ¹ Numeric, character Numeric
Length ¹ 2 to 8 bytes ²

1 to 32,767 bytes for character

8 bytes for numeric, character
Format See Formats. BEST12. for numeric, $w. for character
Informat See Informats. w.d for numeric, $w.for character
Label Up to 256 characters None
Position in observation 1- n NA
Index type NONE, SIMPLE, COMPOSITE, or BOTH. NA
1If not explicitly defined, a variable's type and length are implicitly defined by its first occurrence in a DATA step.

2The minimum length is 2 bytes in some operating environments, 3 in others. See the SAS documentation for your operating environment.


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) or underscore (_). Subsequent characters can be letters, digits (0 to 9), or underscores. Note that blanks are not allowed. Mixed case variables are allowed. See Rules for Words and Names 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 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, the default setting. Other rules apply when this option is set differently. See Rules for Words and Names for more information.  [cautionend]

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 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 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 SAS Indexes 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:

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.


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.