DATA Step, Macro, Functions and more

problems with length

Accepted Solution Solved
Reply
Regular Contributor
Posts: 160
Accepted Solution

problems with length

I have a dataset and want to merge with another dataset but i have different lengths for variables in both the datasets.

In this case i am using length statement to match the lenghts but i get warnings.

data ae010;
 length AESPID $10 AESTDTC AEENDTC $20 AESEV $50 AECONTRT aeser $1;
 set ae010;
run;

WARNING: Multiple lengths were specified for the variable AESPID by input data set(s). This can
cause truncation of data.
WARNING: Multiple lengths were specified for the variable AESEV by input data set(s). This can
cause truncation of data.
WARNING: Multiple lengths were specified for the variable AESER by input data set(s). This can
cause truncation of data.
WARNING: Multiple lengths were specified for the variable AECONTRT by input data set(s). This
can cause truncation of data.
WARNING: Multiple lengths were specified for the variable AESTDTC by input data set(s). This
can cause truncation of data.
WARNING: Multiple lengths were specified for the variable AEENDTC by input data set(s). This


Accepted Solutions
Solution
‎11-30-2016 07:07 AM
Super User
Posts: 7,762

Re: problems with length

This is perfectly normal behaviour. SAS warns you that data may be lost due to truncation.

You might try to use

options VARLENCHK = NOWARN;

before you run the data step.

Take care to reset the option immediately after the step, as these warnings are there for a purpose.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Super User
Posts: 7,942

Re: problems with length

I can't really tell from what you posted there, perhaps some sample test data of both datasets - in the form of a datastep would help explain.  Some thoughts, you can alter length of variables using the proc datasets statement - probably easiest.  You can also SQL join the two datasets as that should take the longest length:

proc sql;
  create table WANT as
  select  coalesce(A.ID,B.ID) as ID length=200
  from    HAVEA A
  full join  HAVEB B
  on       A.ID=B.ID;
quit;
Regular Contributor
Posts: 160

Re: problems with length

in the output i get the length which i changed but i am still getting the warning message.

Solution
‎11-30-2016 07:07 AM
Super User
Posts: 7,762

Re: problems with length

This is perfectly normal behaviour. SAS warns you that data may be lost due to truncation.

You might try to use

options VARLENCHK = NOWARN;

before you run the data step.

Take care to reset the option immediately after the step, as these warnings are there for a purpose.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Super User
Posts: 7,942

Re: problems with length

Well, its up to you what you mark the answer, I would however point out here that all you are doing is hiding the problem and that it might come back to haunt you later on, say when you document ends up on someones desk and half the data has been truncated out.   Its never a good idea to hide problems.

Super User
Posts: 7,762

Re: problems with length

I can only second @RW9's advice. Make your data clean, have strict structures defined, and you won't have such problems. And if you have them, you know that something is wrong with your input data.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 581 views
  • 2 likes
  • 3 in conversation