Actually length has little to do with what is going on with this particular case. It is the behavior of the || operator.
data example1;
length shortvar $ 15;
shortvar = "short";
run;
data example2;
set example1;
shortvar = shortvar || ' long'; /* silently truncates */
run;
The variable is "long enough" but the operator appends to the full length of the the existing variable which is PADDED for the || operation with blanks.
So to ever have a chance you would need to use code like
data example2;
set example1;
shortvar = trim(shortvar) || ' long'; /* silently truncates */
run;
or Strip, or one of CATS or CATT functions.
WHEN the actual cause of the truncation is the length of the variable then add a length statement before the SET but you still to address the behavior of || .
data example1;
shortvar = "short";
run;
data example2;
length shortvar $ 15;
set example1;
shortvar = trim(shortvar) || ' long'; /* silently truncates */
run;
... View more