I have a variable called ID on dataset OLD, and I need to change the length from 13 to 12 for a merge. Below is the metadata associated with this variable.
Variable Type Len Format Informat Label
ID Char 13 $12. $12. 'Person ID'
(The contents of each value for ID is always exactly 12 characters in this file)
When I try to edit the length before the set statement in a DATA step, I get a warning. The same happens when I edit both the length and the format.
data NEW;
length ID $12;
format ID $12.;
set OLD;
run;
...
WARNING: Multiple lengths were specified for the variable AN_RESEARCHID by
input data set(s). This can cause truncation of data.
Examples from SAS community forums don't seem to describe why this warning would occur, or how to avoid it. Any thoughts?
You could rename the original variable in your SET statement, and create a new variable with your desired length. Then set the new variable equal to the old within the data step. You won't get the warning. But of course what it warns you about still holds- that is, if your data does happen to have 13 characters, it'll truncate the value when jamming it into a variable with a shorter length.