Monday, November 12, 2012

SAS options varlenchk=

How many times have you seen this warning in SAS?

WARNING: Multiple lengths were specified for the variable {VARNAME} by input data
set(s). This may cause truncation of data.

This can become a common warning when you're manipulating SAS datasets and resizing variables, for example, to meet data dictionary specifications. In general, you want to know about possible data truncation, but there are occasions when you know what the data look like and you purposefully want to shrink the length of a variable. For example, let's say you get a feed from another database system and the length of the variable in question is char(100). You know that the max length of data is char(20), so you want to shrink the data to size char(30). The name of the input dataset is called source_data.

data my_data;
    length text_field $30.; *char(100) in source_data dataset;
    set source_data;
run;

By itself, this will generate the warning, however if you surround the data step with options like this, the resizing warning will be suppressed and your SAS log will be kept clear of false warnings.

options varlenchk=nowarn; *temporarily turn off variable length checking since purposefully resizing vars;
data my_data;
    length text_field $30.; *char(100) in source_data dataset;
    set source_data;
run;
options varlenchk=warn; *turn variable length checking back on;