A SAS variable has the
attributes that are listed in the following table:
Variable Attributes
|
|
|
|
|
|
|
|
|
|
1 to 32,767 bytes for
character
|
8 bytes for numeric
and character
|
|
|
BEST12. for numeric,
$w. for character
|
|
|
w.d for numeric, $w.for
character
|
|
|
|
|
|
|
|
NONE, SIMPLE, COMPOSITE,
or BOTH
|
|
1If they are 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 bytes in 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 depends on your environment and the file's attributes.
For example, the maximum number of variables depends on the total
length of all the variables and cannot exceed the maximum page size.
You can use the CONTENTS
procedure, or the functions that are named in the following definitions,
to obtain information about a variable's attributes:
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 used. Mixed-case variables are used. See
Rules for Words and Names in the SAS Language for more details about 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, which is the default setting. Other
rules apply when this option is set differently. See
Rules for Words and Names in the SAS Language for more information.
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.
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.
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.
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.
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.
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.
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
|
|
|
The variable is not
indexed.
|
|
The variable is part
of a simple index.
|
|
The variable is part
of one or more composite indexes.
|
|
The variable is part
of both simple and composite indexes.
|