MERGE statement contain the variable Mileage. In Quarter1, the length of the
variable Mileage is four bytes; in Quarter2, it is eight bytes and in Quarter3 and
Quarter4, it is six bytes. In the output data set Yearly, the length of the variable
Mileage is four bytes, which is the length derived from Quarter1.
data yearly;
merge quarter1 quarter2 quarter3 quarter4;
by Account;
run;
To override the default and set the length yourself, specify the appropriate length
in a LENGTH statement that precedes the SET, MERGE, or UPDATE statement.
Note: If the length of a variable changes as a result of combining data sets, SAS
prints a warning message to the log and issues a nonzero return code (for
example, on z/OS, SYSRC=4). If you expect truncation of data (for example,
when removing insignificant blanks from the end of character values), the
warning is expected and you do not want SAS to issue a nonzero return code.
In this case, you can turn this warning off by setting the VARLENCHK
system option to NOWARN. For more information, see “VARLENCHK=
System Option” in SAS System Options: Reference.
• label, format, and informat attributes
If any of these attributes are different, SAS takes the attribute from the first data
set that contains the variable with that attribute. However, any label, format, or
informat that you explicitly specify overrides a default. If all data sets contain
explicitly specified attributes, the one specified in the first data set overrides the
others. To ensure that the new output data set has the attributes that you prefer,
use an ATTRIB statement.
You can also use SAS File I/O functions, such as VLABEL, VLABELX, and
other Variable Information functions to access this information. For complete
information about these functions, see SAS Functions and CALL Routines:
Reference.
• extended attributes
Like formats and labels, extended attributes are automatically passed from the
input data set to the output data set in a DATA step. If two input data sets
containing extended attributes are combined, then SAS preserves the extended
attributes from the first data set seen in the program where the variable is read
and applies those attributes to the output data set. To ensure that the new output
data set has the extended attributes that you prefer, use the DATASETS
procedure to add, delete, remove, set, and update extended attributes. For more
information about the DATASETS procedure see “Extended Attributes” in Base
SAS Procedures Guide.
Ensuring Correct Order
If you use BY-group processing with the UPDATE, SET, and MERGE statements to
combine data sets, ensure that the observations in the data sets are sorted in the order of
the variables that are listed in the BY statement, or that the data sets have an appropriate
index. If you use BY-group processing in a MODIFY statement, your data does not need
to be sorted, but sorting the data improves efficiency. The BY variable or variables must
be common to both data sets, and they must have the same attributes. For more
information, see Chapter 20, “BY-Group Processing in the DATA Step,” on page 449.
Combining SAS Data Sets: Basic Concepts 477