I want to append two files but it is throwing a warning:
WARNING: Variable defaultname has different lengths on BASE and DATA files (BASE 70 DATA 100).
How it can be resolved
Hi,
the:
data <data table>;
if 0 then set <base table>;
set <data table>;
run;
approach will still generate warning, e.g.
1 2 data BASE; 3 length defaultname $ 70; 4 defaultname = "Alice"; 5 run; NOTE: The data set WORK.BASE has 1 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds 6 7 data DATA; 8 length defaultname $ 100; 9 defaultname = "Bob"; 10 run; NOTE: The data set WORK.DATA has 1 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds 11 12 data DATA; 13 if 0 then set BASE; 14 set DATA; 15 run; WARNING: Multiple lengths were specified for the variable defaultname by input data set(s). This can cause truncation of data. NOTE: There were 1 observations read from the data set WORK.DATA. NOTE: The data set WORK.DATA has 1 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds
But this one:
data DATA;
set DATA;
length _tmp_ $ 70;
_tmp_ = defaultname;
drop defaultname;
rename _tmp_ = defaultname;
run;
won't:
11 12 data DATA; 13 set DATA; 14 length _tmp_ $ 70; 15 _tmp_ = defaultname; 16 drop defaultname; 17 rename _tmp_ = defaultname; 18 run; NOTE: There were 1 observations read from the data set WORK.DATA. NOTE: The data set WORK.DATA has 1 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
All the best
Bart
Please try something as below
data want;
length defaultname $100;
set base data;
run;
Hi @annypanny
SAS put a warning in the log because it "wonders" if the variable "defautlname" refers to the same variable. Indeed, this variable is present in both input datasets and has common caracteristics: same type (otherwise you would have an error in the log) and same name. However, the length differs.
To avoid this issue, you need to tell SAS what is the appropriate length first. To do that, you can specify it in a LENGTH statement. The PDV containing the variable definition is then correctly set up before filling in the dataset with the original values.
Best,
The ideal solution (and the one you should pursue) is to create all common variables with identical attributes in the first place. How you do this depends on the method used to get data into SAS.
First of all: Congrats that you're reading the SAS log. Too many people aren't and I'm right now in a project where I have to clean-up such mess.
The Warning indicates that you're appending a column with a length of 70 to a base table with the same named column with a length of 100. Because the length of the column in the Base table is longer nothing bad like actual string truncation will happen.
Ideally a variable with the same name always means the same and has the same attributes (including the length) throughout your application. So if you really want to tidy up things that's what you should try to achieve and figure out why this is not the case.
You can "force" the column attributes of your data table to be the same as your base table via a preliminary SAS data step in the form of:
data <data table>; if 0 then set <base table>; set <data table>; run; proc append base=<base table> data=<data table>; run;
Hi,
the:
data <data table>;
if 0 then set <base table>;
set <data table>;
run;
approach will still generate warning, e.g.
1 2 data BASE; 3 length defaultname $ 70; 4 defaultname = "Alice"; 5 run; NOTE: The data set WORK.BASE has 1 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds 6 7 data DATA; 8 length defaultname $ 100; 9 defaultname = "Bob"; 10 run; NOTE: The data set WORK.DATA has 1 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds 11 12 data DATA; 13 if 0 then set BASE; 14 set DATA; 15 run; WARNING: Multiple lengths were specified for the variable defaultname by input data set(s). This can cause truncation of data. NOTE: There were 1 observations read from the data set WORK.DATA. NOTE: The data set WORK.DATA has 1 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds
But this one:
data DATA;
set DATA;
length _tmp_ $ 70;
_tmp_ = defaultname;
drop defaultname;
rename _tmp_ = defaultname;
run;
won't:
11 12 data DATA; 13 set DATA; 14 length _tmp_ $ 70; 15 _tmp_ = defaultname; 16 drop defaultname; 17 rename _tmp_ = defaultname; 18 run; NOTE: There were 1 observations read from the data set WORK.DATA. NOTE: The data set WORK.DATA has 1 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
All the best
Bart
Please include Log code with any concerns about Warnings, Notes or Error messages.
Please copy from the log the entire data step or procedure involved and paste into a code box opened on the forum using the </> icon to preserve formatting.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.