BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
annypanny
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

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

 

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

8 REPLIES 8
yabwon
Onyx | Level 15
change the `defaultname` variable length in DATA from 100 to 70
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Jagadishkatam
Amethyst | Level 16

Please try something as below

 

data want;
length defaultname $100;
set base data;
run;
Thanks,
Jag
ed_sas_member
Meteorite | Level 14

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,

Kurt_Bremser
Super User

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.

Patrick
Opal | Level 21

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;

 

 

yabwon
Onyx | Level 15

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

 

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



annypanny
Quartz | Level 8
Thank you, but above code throws a warning:
WARNING: Multiple lengths were specified for the variable defaultname by input data set(s). This can cause truncation of data.
ballardw
Super User

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.

 

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 8 replies
  • 1236 views
  • 5 likes
  • 7 in conversation