Problem Note 54601: A LENGTH statement for a numeric variable that is positioned after a SET statement might cause truncation of data and no warning message is issued
Truncation of data can occur and no warning message is issued if a LENGTH statement for a numeric variable is positioned after a SET statement in a DATA step.
The following example code illustrates the problem:
data test1;
length var1 $10 var2 8;
do i = 1 to 50;
var1='hello';
var2=65537;
output;
end;
run;
data test2;
set test1;
length var2 3;
by var2;
run;
To circumvent the problem, place the LENGTH statement before the SET statement in your DATA step code.
When a LENGTH statement is positioned before a SET statement, the following warning is generated if the length of the variable in the LENGTH statement is shorter than the specified variable being read in with the SET statement, :
WARNING: Multiple lengths were specified for the BY variable var2 by input data sets and LENGTH,
FORMAT, INFORMAT, or ATTRIB statements. This may cause unexpected results.
The following example code illustrates this:
data test1;
length var1 $10 var2 8;
do i = 1 to 50;
var1='hello';
var2=65537;
output;
end;
run;
data test2;
length var2 3;
set test1 ;
by var2;
run;
Operating System and Release Information
| SAS System | Base SAS | Linux | 9.3 TS1M2 | |
| Linux for x64 | 9.3 TS1M2 | |
| Solaris for x64 | 9.3 TS1M2 | |
| HP-UX IPF | 9.3 TS1M2 | |
| 64-bit Enabled Solaris | 9.3 TS1M2 | |
| 64-bit Enabled HP-UX | 9.3 TS1M2 | |
| 64-bit Enabled AIX | 9.3 TS1M2 | |
| Windows Vista for x64 | 9.3 TS1M2 | |
| Windows Vista | 9.3 TS1M2 | |
| Windows 7 Ultimate x64 | 9.3 TS1M2 | |
| Windows 7 Ultimate 32 bit | 9.3 TS1M2 | |
| Windows 7 Professional x64 | 9.3 TS1M2 | |
| Windows 7 Professional 32 bit | 9.3 TS1M2 | |
| Windows 7 Home Premium x64 | 9.3 TS1M2 | |
| Windows 7 Home Premium 32 bit | 9.3 TS1M2 | |
| Windows 7 Enterprise x64 | 9.3 TS1M2 | |
| Windows 7 Enterprise 32 bit | 9.3 TS1M2 | |
| Microsoft Windows XP Professional | 9.3 TS1M2 | |
| Microsoft Windows Server 2012 Std | 9.3 TS1M2 | |
| Microsoft Windows Server 2012 R2 Std | 9.3 TS1M2 | |
| Microsoft Windows Server 2012 R2 Datacenter | 9.3 TS1M2 | |
| Microsoft Windows Server 2012 Datacenter | 9.3 TS1M2 | |
| Microsoft Windows Server 2008 for x64 | 9.3 TS1M2 | |
| Microsoft Windows Server 2008 R2 | 9.3 TS1M2 | |
| Microsoft Windows Server 2008 | 9.3 TS1M2 | |
| Microsoft Windows Server 2003 for x64 | 9.3 TS1M2 | |
| Microsoft Windows Server 2003 Standard Edition | 9.3 TS1M2 | |
| Microsoft Windows Server 2003 Enterprise Edition | 9.3 TS1M2 | |
| Microsoft Windows Server 2003 Datacenter Edition | 9.3 TS1M2 | |
| Microsoft Windows 8.1 Pro 32-bit | 9.3 TS1M2 | |
| Microsoft Windows 8.1 Pro | 9.3 TS1M2 | |
| Microsoft Windows 8.1 Enterprise x64 | 9.3 TS1M2 | |
| Microsoft Windows 8.1 Enterprise 32-bit | 9.3 TS1M2 | |
| Microsoft Windows 8 Pro x64 | 9.3 TS1M2 | |
| Microsoft Windows 8 Pro 32-bit | 9.3 TS1M2 | |
| Microsoft Windows 8 Enterprise x64 | 9.3 TS1M2 | |
| Microsoft Windows 8 Enterprise 32-bit | 9.3 TS1M2 | |
| Microsoft® Windows® for x64 | 9.3 TS1M2 | |
| Z64 | 9.3 TS1M2 | |
| z/OS | 9.3 TS1M2 | |
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
| Type: | Problem Note |
| Priority: | high |
| Date Modified: | 2014-11-19 15:23:59 |
| Date Created: | 2014-11-11 17:58:27 |