Hi,
I think this is a simple solution, but I can't seem to figure it out.
I have multiple datasets in the exact same data layout that i'd like to concatenate using the data step.
for example:
data merged ;
set table1 table2 table3 table4 ;
run ;
A variable may have different lengths in each of the tables so when I run the code above I get the warning:
"Multiple lengths were specified for the variable Product by input data set(s). This may cause truncation of data."
I tried adding the length statement but still got the warning.
How can I set the length so I do not get the warning?
Thanks for your help.
options varlenchk=nowarn;
I can't test this at the moment, but do you still get the error if the place the length statement(s) before the set statement?
yes the warning still shows up if do:
data merged ;
length product $15 ;
set table1 table2 table3 table4 ;
run ;
How about if, in your set statement, you put the file with the longest lengths first (leftmost) on the list?
My limited testing shows that if you still have the warning it means that one or more of the varables from the input data sets have a length longer than you have defined. You could use PROC CONTENTS and PROC SUMMARY to determine the MAX length of each variable and code gen LENGTH/ATTRIB statements to resolve the issue.
Is their a way to force the length for the new dataset?
for example:
table1: Product $15
table2: Product $15
table3: Product $17
table4: Product $15
for some reason i have some dirty records in table3 that makes the product variable $17, In my merged dataset I want to make product $15, and its fine if its truncated.
You are doing that with the length statement or by ensuring that the culprit is not the first file. Or are you asking how to do it without having to confront the warnings?
yes exactly, is there a way around the warning?
options varlenchk=nowarn;
Great thanks for your help.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.