This DATA step produces a SAS data set with the following variable values:
OBS X Y
1 4 .
2 1 2
3 3 .
4 1 2
When X equals 1, the value of Y is set to 2. Since no other statements set Y's value when
X is not equal to 1, Y remains missing (.) for those observations.
When Reading a SAS Data Set
When variables are read with a SET, MERGE, or UPDATE statement, SAS sets the
values to missing only before the first iteration of the DATA step. (If you use a BY
statement, the variable values are also set to missing when the BY group changes.) The
variables retain their values until new values become available (for example, through an
assignment statement or through the next execution of the SET, MERGE, or UPDATE
statement). Variables created with options in the SET, MERGE, and UPDATE statements
also retain their values from one iteration to the next.
When all rows in a data set in a match-merge operation (with a BY statement) are
processed, the variables in the output data set retain their values as described earlier.
That is, as long as there is no change in the BY value in effect when all of the rows in the
data set have been processed, the variables in the output data set retain their values from
the final observation. FIRST.variable and LAST.variable, the automatic variables that are
generated by the BY statement, both retain their values. Their initial value is 1.
When the BY value changes, the variables are set to missing and remain missing because
the data set contains no additional observations to provide replacement values. When all
of the rows in a data set in a one-to-one merge operation (without a BY statement) have
been processed, the variables in the output data set are set to missing and remain
missing.
When Missing Values Are Generated by SAS
Propagation of Missing Values in Calculations
SAS assigns missing values to prevent problems from arising. If you use a missing value
in an arithmetic calculation, SAS sets the result of that calculation to missing. Then, if
you use that result in another calculation, the next result is also missing. This action is
called propagation of missing values. SAS prints notes in the log to notify you which
arithmetic expressions have missing values and when they were created. However,
processing continues.
Invalid Operations
SAS prints a note in the log and assigns a missing value to the result if you try to
perform an invalid operation, such as the following:
dividing by zero
taking the logarithm of zero
When Missing Values Are Generated by SAS 87
using an expression to produce a number too large to be represented as a floating-
point number (known as overflow)
Invalid Character-to-Numeric Conversions
SAS automatically converts character values to numeric values if a character variable is
used in an arithmetic expression. If a character value contains nonnumerical information
and SAS tries to convert it to a numeric value, a note is printed in the log, the result of
the conversion is set to missing, and the _ERROR_ automatic variable is set to 1.
Creating Special Missing Values
The result of any numeric missing value in a SAS expression is a period. Thus, both
special missing values and ordinary numeric missing values propagate as a period.
data a;
x=.d;
y=x+1;
put y=;
run;
This DATA step results in the following log:
Log 5.1 SAS Log Results for a Missing Value
130 data a;
131 x=.d;
132 y=x+1;
133 put y=;
134 run;
y=.
NOTE: Missing values were generated as a result of performing an operation on
missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at 132:10
NOTE: The data set WORK.A has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
Preventing Propagation of Missing Values
If you do not want missing values to propagate in your arithmetic expressions, you can
omit missing values from computations by using the sample statistic functions. For
example, consider the following DATA step:
data test;
x=.;
y=5;
a=x+y;
b=sum(x,y);
c=5;
c+x;
put a= b= c=;
run;
88 Chapter 5 Missing Values

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.