SAS System Options |
Valid in: | configuration file, SAS invocation, OPTIONS statement, SAS System Options window |
Category: | Files: SAS Files |
PROC OPTIONS GROUP= | SASFILES |
Syntax |
VARLENCHK=NOWARN | WARN | ERROR |
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.
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. This is the default.
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 |
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 MODFIY 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. By using the shorter length, data will not 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.
Examples |
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. +1 Exam_Date mmddyy10.; format Exam_Date mmddyy10.; datalines; Carol 06/09/2008 Hui 06/09/2008 Janet 06/09/2008 Geoffrey 06/09/2008 John 06/09/2008 Joyce 06/09/2008 Helga 06/09/2008 Mary 06/09/2008 Roberto 06/09/2008 Ronald 06/09/2008 Barbara 06/10/2008 Louise 06/10/2008 Alfred 06/11/2008 Alice 06/11/2008 Henri 06/11/2008 James 06/11/2008 Philip 06/11/2008 Tomas 06/11/2008 William 06/11/2008
/* 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
1 data exam_schedule(index=(Name)); 2 input Name $10. +1 Exam_Date mmddyy10.; 3 format Exam_Date mmddyy10.; 4 datalines; NOTE: The data set WORK.EXAM_SCHEDULE has 20 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 4.32 seconds cpu time 0.24 seconds 25 ; 26 27 data exams; 28 set sashelp.class; 29 set exam_schedule key=Name; 30 run; WARNING: Multiple lengths were specified for the variable Name by input data set(s). This may cause truncation of data. NOTE: There were 19 observations read from the data set SASHELP.CLASS. NOTE: The data set WORK.EXAMS has 19 observations and 6 variables. NOTE: DATA statement used (Total process time): real time 0.51 seconds cpu time 0.00 seconds
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:
37 options varlenchk=nowarn; 38 options varlenchk=nowarn; 39 data exam_schedule(index=(Name)); 40 length Name $ 8; 41 set exam_schedule; 42 run; NOTE: There were 20 observations read from the data set WORK.EXAM_SCHEDULE. NOTE: The data set WORK.EXAM_SCHEDULE has 20 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
See Also |
Looking at Sources of Common Problems in the "Combining SAS Data Sets: Basic Concepts" section of SAS Language Reference: Concepts |
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.