VARLENCHK= System Option

Specifies the type of message to write to the SAS log when the input data set is read using the SET, MERGE, UPDATE, or MODIFY statements.

Valid in: Configuration file, SAS invocation, OPTIONS statement, SAS System Options window
Category: Files: SAS Files
PROC OPTIONS GROUP= SASFILES
Default: The shipped default is WARN.
Note: This option can be restricted by a site administrator. For more information, see Restricted Options.

Syntax

VARLENCHK=NOWARN | WARN | ERROR

Syntax Description

NOWARN

specifies that no warning message is issued when the length of a variable that is being read is larger than the length that is defined for the variable.

WARN

specifies that a warning is issued when the length of a variable that is being read is larger than the length that is defined for the variable.

ERROR

specifies that an error message is issued when the length of a variable that is being read is larger than the length that is defined for the variable.

Details

CAUTION:
Data might be truncated if you change the length of a variable.
After a variable is defined, the length of a variable can be changed only by a LENGTH statement. If a variable is read by the SET, MERGE, UPDATE, or MODIFY statements and the length of the variable is longer than a variable of the same name, SAS issues a warning message and uses the shorter, original length of the variable. Because SAS uses the shorter length, data might be truncated.
When you intentionally truncate data, perhaps to remove unnecessary blanks from character variables, SAS issues a warning message that might not be useful to you. To make it so that SAS does not issue the warning message or set a nonzero return code, you can set the VARLENCHK= system option to NOWARN. When VARLENCHK=NOWARN, SAS does not issue a warning message and sets the return code to SYSRC=0.
Alternatively, if you set VARLENCHK=ERROR and the length of a variable that is being read is larger than the length that is defined for the variable, SAS issues an error and sets the return code SYSRC=8.
The VARLENCHECK= system option does not have any effect on BY variables named in a BY statement that follows a SET, MERGE, or UPDATE statement. The VARLENCHK= option applies only to variables with the same name that have different lengths in two or more data sets. BY variables are excluded by design.
Note: When a BY variable has different lengths in two or more data sets, a separate warning message is produced, which is the correct behavior.
WARNING: Multiple lengths were specified for the BY variable x by input data sets. This may cause unexpected results.
To avoid this warning message, you can specify the LENGTH statement prior to the SET, MERGE, or UPDATE statement to set the BY variable to the same length.

Examples

Example 1: SAS Issues a Warning Message Merging Two Data Sets with Different Variable Lengths

This example merges two data sets, the sashelp.class data set and the exam_schedule data set. The length of the variable Name is set to 8 by the first SET statement, set sashelp.class;. The exam_schedule data set sets the length of Name to 10. When exam_schedule is read in the second SET statement, set exam_schedule key=Name;, SAS issues a warning message because the length of Name in the exam_schedule data set is longer than the length of Name in the sashelp.class data set, and data might have been truncated.
/* Create the exam_schedule data set. */
data exam_schedule(index=(Name));
  input Name : $10. Exam_Date : mmddyy10.;
  format Exam_Date mmddyy10.;
datalines;
Carol      06/09/2011
Hui         06/09/2011
Janet      06/09/2011
Geoffrey 06/09/2011
John        06/09/2011
Joyce       06/09/2011
Helga      06/09/2011
Mary       06/09/2011
Roberto   06/09/2011
Ronald     06/09/2011
Barbara    06/10/2011
Louise     06/10/2011
Alfred     06/11/2011
Alice      06/11/2011
Henri      06/11/2011
James      06/11/2011
Philip     06/11/2011
Tomas     06/11/2011
William    06/11/2011
;
run

/* Merge the data sets sashelp.class and exam_schedule  */
data exams;
  set sashelp.class;
  set exam_schedule key=Name;
run;
The following SAS log shows the warning message:
The Warning Message in the SAS Log
34   ods listing;
35   /* Create the exam_schedule data set. */
36   data exam_schedule(index=(Name));
37     input Name : $10. Exam_Date : mmddyy10.;
38     format Exam_Date mmddyy10.;
39   datalines;

NOTE: The data set WORK.EXAM_SCHEDULE has 19 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.09 seconds
      cpu time            0.00 seconds


59   ;
60   run;
61
62   /* Merge the data sets sashelp.class and exam_schedule  */
63   data exams;
64     set sashelp.class;
65     set exam_schedule key=Name;
66   run;

WARNING: Multiple lengths were specified for the variable Name by input data set(s). This may cause truncation of data.
Name=Henry Sex=M Age=14 Height=63.5 Weight=102.5 Exam_Date=06/09/2011 _ERROR_=1 _IORC_=1230015 _N_=5
Name=Jane Sex=F Age=12 Height=59.8 Weight=84.5 Exam_Date=06/11/2011 _ERROR_=1 _IORC_=1230015 _N_=7
Name=Jeffrey Sex=M Age=13 Height=62.5 Weight=84 Exam_Date=06/09/2011 _ERROR_=1 _IORC_=1230015 _N_=9
Name=Judy Sex=F Age=14 Height=64.3 Weight=90 Exam_Date=06/09/2011 _ERROR_=1 _IORC_=1230015 _N_=12
Name=Robert Sex=M Age=12 Height=64.8 Weight=128 Exam_Date=06/11/2011 _ERROR_=1 _IORC_=1230015 _N_=16
Name=Thomas Sex=M Age=11 Height=57.5 Weight=85 Exam_Date=06/09/2011 _ERROR_=1 _IORC_=1230015 _N_=18
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.EXAMS has 19 observations and 6 variables.

Example 2: Turn Off the Warning Message and Use the LENGTH Statement to Match Variable Lengths

In order to merge the two data sets, sashelp.class and exam_schedule, you can examine the values of Name in exam_schedule. You can see that there are no values that are greater than 8 and that you can change the length of Name without losing data.
To change the length of the variable Name, you use a LENGTH= statement in a DATA step before the set exam_schedule; statement. If the value of VARLENCHK is WARN (the default), SAS issues the warning message that the value of Name is truncated when it is read from work.exam_schedule. Because you know that data is not lost, you might want to turn the warning message off:
options varlenchk=nowarn;
data exam_schedule(index=(Name));
  length Name $ 8;
  set exam_schedule;
run;
The following is the SAS log output:
67   options varlenchk=nowarn;
68   data exam_schedule(index=(Name));
69     length Name $ 8;
70     set exam_schedule;
71   run;

NOTE: There were 19 observations read from the data set WORK.EXAM_SCHEDULE.
NOTE: The data set WORK.EXAM_SCHEDULE has 19 observations and 2 variables.

See Also

Looking at Sources of Common Problems in SAS Language Reference: Concepts