I'm getting this warning for diagnosis code which has varying lengths - the longest (including the decimal) is 7.
How do I fix it so that I stop getting this error? I tried the below:
23 data aa_dd;
24 length icd $7;
25 merge aa(in=ina)
26 diag;
27 by claimHeaderId;
28 if ina;
29
30 run;
WARNING: Multiple lengths were specified for the variable icd by input data set(s). This can cause truncation of data.
Compare the variable lengths in the 2 datasets aa and diag
My guess is you have a common variable on both datasets that has different lengths defined.
You might want to run a PROC CONTENTS on them both
Here's a simple example:
data test10 ;
length a $10 ;
a="1234567890" ;
output ;
run ;
data test8 ;
length a $8 ;
a="12345678" ;
output ;
run ;
data join ;
set test8 test10 ;
run ;
and here's the log:
2 data test10 ;
3 length a $10 ;
4 a="1234567890" ;
5 output ;
6 run ;
NOTE: The data set WORK.TEST10 has 1 observations and 1 variables.
NOTE: At least one W.D format was too small for the number to be printed. The decimal may be
shifted by the "BEST" format.
NOTE: DATA statement used (Total process time):
real time 0.13 seconds
cpu time 0.00 seconds
7
8 data test8 ;
9 length a $8 ;
10 a="12345678" ;
11 output ;
12 run ;
NOTE: The data set WORK.TEST8 has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
13
14 data join ;
15 set test8 test10 ;
16 run ;
WARNING: Multiple lengths were specified for the variable a by input data set(s). This can cause
truncation of data.
NOTE: There were 1 observations read from the data set WORK.TEST8.
NOTE: There were 1 observations read from the data set WORK.TEST10.
NOTE: The data set WORK.JOIN has 2 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.03 seconds
Compare the variable lengths in the 2 datasets aa and diag
My guess is you have a common variable on both datasets that has different lengths defined.
You might want to run a PROC CONTENTS on them both
Here's a simple example:
data test10 ;
length a $10 ;
a="1234567890" ;
output ;
run ;
data test8 ;
length a $8 ;
a="12345678" ;
output ;
run ;
data join ;
set test8 test10 ;
run ;
and here's the log:
2 data test10 ;
3 length a $10 ;
4 a="1234567890" ;
5 output ;
6 run ;
NOTE: The data set WORK.TEST10 has 1 observations and 1 variables.
NOTE: At least one W.D format was too small for the number to be printed. The decimal may be
shifted by the "BEST" format.
NOTE: DATA statement used (Total process time):
real time 0.13 seconds
cpu time 0.00 seconds
7
8 data test8 ;
9 length a $8 ;
10 a="12345678" ;
11 output ;
12 run ;
NOTE: The data set WORK.TEST8 has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
13
14 data join ;
15 set test8 test10 ;
16 run ;
WARNING: Multiple lengths were specified for the variable a by input data set(s). This can cause
truncation of data.
NOTE: There were 1 observations read from the data set WORK.TEST8.
NOTE: There were 1 observations read from the data set WORK.TEST10.
NOTE: The data set WORK.JOIN has 2 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.03 seconds
Yes, typically you would want to use the length of the longest character variable
If you run the simple test code, you'll notice that the work.join dataset ends up truncating the second observations from "1234567890" to "12345678" (Not Good)
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.