Table 4.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.
extended attribute
is a user-defined attribute that is created using the XATTR ADD VAR statement in
the DATASETS procedure. For more information, see “Extended Attributes” in Base
SAS Procedures Guide.
Ways to Create Variables
Overview
These are some of the most common ways that you can create variables in a DATA step:
Use an assignment statement.
Read data with the INPUT statement in a DATA step.
Specify a new variable in a FORMAT or INFORMAT statement.
Specify a new variable in a LENGTH statement.
Specify a new variable in an ATTRIB statement.
Note: This list is not exhaustive. For example, the SET, MERGE, MODIFY, and
UPDATE statements can also create variables.
Using an Assignment Statement
In a DATA step, you can create a new variable and assign it a value by using it for the
first time on the left side of an assignment statement. If a variable is created using an
assignment statement, both its type and length must be implicitely defined by SAS.
SAS determines the length and type of the variable from its first occurrence in the DATA
step. The variable gets the same type and length as the expression on the right side of the
assignment statement.
When the type and length of a variable are not explicitly set, SAS gives the variable a
default type and length, as shown in the examples in the following table.
Ways to Create Variables 41
Table 4.3 Resulting Variable Types and Lengths Produced When They Are Not Explicitly Set
Expression Example
Resulting
Type of X
Resulting
Length of X Explanation
Numeric
variable
length a 4;
x=a;
Numeric
variable
8 Default numeric
length (8 bytes
unless otherwise
specified)
Character
variable
length a $ 4;
x=a;
Character
variable
4 Length of source
variable
Character literal
x='ABC';
x='ABCDE';
Character
variable
3 Length of first
literal
encountered
Concatenation
of variables
length a $ 4
b $ 6
c $ 2;
x=a||b||c;
Character
variable
12 Sum of the
lengths of all
variables
Concatenation
of variables and
literal
length a $ 4;
x=a||'CAT';
x=a||'CATNIP'
;
Character
variable
7 Sum of the
lengths of
variables and
literals
encountered in
first assignment
statement
If a variable appears for the first time on the right side of an assignment statement, SAS
assumes that it is a numeric variable and that its value is missing. If no later statement
gives it a value, SAS prints a note in the log that the variable is not initialized. Instead of
issuing a note in the SAS log, you can use the VARINITCHK= system option to specify
that no note is to be written to the SAS log, or to specify that a warning or an error
message is to be written to the SAS log. If an error is set, the DATA step stops
processing. For more information, see “VARINITCHK= System Option” in SAS System
Options: Reference.
Note: A RETAIN statement initializes a variable and can assign it an initial value, even
if the RETAIN statement appears after the assignment statement.
when you create a variable using the INPUT statement, it is considered “explicitely”
declared even if you do not explicitly assign the length.
Reading Data with the INPUT Statement in a DATA Step
When you read raw data in SAS by using an INPUT statement, you define variables
based on positions in the raw data. You can use one of the following methods with the
INPUT statement to provide information to SAS about how the raw data is organized:
column input
list input (simple or modified)
formatted input
42 Chapter 4 SAS Variables

Get SAS 9.4 Language Reference, 6th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.