Desktop productivity for business analysts and programmers

WARNING: Multiple lengths were specified for the BY variable WEEK_END_DT by input data sets and LENG

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 108
Accepted Solution

WARNING: Multiple lengths were specified for the BY variable WEEK_END_DT by input data sets and LENG

[ Edited ]

Hi All,

 

I'm getting this error when I merge two data steps together which has originated from the same data table.

 

Data work.MergeBranches2;
	Merge work.MergeBranches1 work.NetworkTRANSSUM;
	by WEEK_END_DT;

RUN;

 

 

WARNING: Multiple lengths were specified for the BY variable WEEK_END_DT by input data sets and LENGTH, FORMAT, INFORMAT, or ATTRIB statements. This might cause unexpected results.

 

I have used Format WEEK_END_DT DDMMYY10.; to format the dates in the data steps but still get the same error.

 

 

Data work.NetworkSimpTrans;
	Keep WEEK_END_DT TRANSCNT CALLS ;
	SET work.Data;
	WHERE EVENT_DT between "&DATEVAR1"d and "&DATEVAR"d
		AND Origin_cd in (&FullList)
		;
Format WEEK_END_DT DDMMYY10.;
	
RUN;

It seems to merge the data together ok - should I be worried about 'unexpected results', is there a way I can stop this error from happening?

 

The merge looks like this and seems to have no problems with the dates

WEEK_END_DTCallsTrans1Calls2Trans2Calls3Trans3Calls4Trans4TRANS_CNTCALLS
18/02/201833411501730738439433431540649582834924454155363
25/02/201832423449130015449938112615946175784924332155993
04/03/201833981402630184378736763614049303783522884160005
11/03/201832509419729403322036842554045554678020538153633

 

 

 

Any help appreciated.  

 

Dean

 

 

 

 


Accepted Solutions
Solution
‎03-15-2018 07:58 PM
Super User
Posts: 13,084

Re: WARNING: Multiple lengths were specified for the BY variable WEEK_END_DT by input data sets and

[ Edited ]

Run Proc contents on both of those data sets. Examine the LENGTH characteristic for the variable in each set.

 

Length for variables indicates how many bytes are set aside by SAS to store a variable. When the lengths are different in the two sets SAS issues that warning because if the shorter length occurs in the first named data set the values from the second set may be truncated.

 

Please see this code for an example of the results that is pretty easy to see.

data example;
   length x 3 word $ 4;
   x = 3;
   word = 'Word';
run;

data example2;
   length x 8 word $ 20;
   x=123456789;
   word='Somethinglongerthan4';
run;

data combined;
   set example example2;
run;

proc print;
run;

Notice the value of both variables in the second row of the output do not match what was created for the second data set.

 

 

The fix if you actually have data issues can be very simple by adding a length statement before the SET statement. The length statement should use the larger value that appears for either data set.

data combined;
   length x 8 word $ 20;
   set example example2;
run;

 

BTW that is not an ERROR. An actual error would stop the execution. SAS is warning you that you might get unexpected results and should revisit the data descriptions.

View solution in original post


All Replies
Solution
‎03-15-2018 07:58 PM
Super User
Posts: 13,084

Re: WARNING: Multiple lengths were specified for the BY variable WEEK_END_DT by input data sets and

[ Edited ]

Run Proc contents on both of those data sets. Examine the LENGTH characteristic for the variable in each set.

 

Length for variables indicates how many bytes are set aside by SAS to store a variable. When the lengths are different in the two sets SAS issues that warning because if the shorter length occurs in the first named data set the values from the second set may be truncated.

 

Please see this code for an example of the results that is pretty easy to see.

data example;
   length x 3 word $ 4;
   x = 3;
   word = 'Word';
run;

data example2;
   length x 8 word $ 20;
   x=123456789;
   word='Somethinglongerthan4';
run;

data combined;
   set example example2;
run;

proc print;
run;

Notice the value of both variables in the second row of the output do not match what was created for the second data set.

 

 

The fix if you actually have data issues can be very simple by adding a length statement before the SET statement. The length statement should use the larger value that appears for either data set.

data combined;
   length x 8 word $ 20;
   set example example2;
run;

 

BTW that is not an ERROR. An actual error would stop the execution. SAS is warning you that you might get unexpected results and should revisit the data descriptions.

Frequent Contributor
Posts: 108

Re: WARNING: Multiple lengths were specified for the BY variable WEEK_END_DT by input data sets and

Thanks #ballardw,

 

Thought I had used the same table but is a different one and yes one date length was 5 and the other was 8.

 

Will keep Proc Contents in mind for next time.

 

Cheers

 

Dean

 

 

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 420 views
  • 1 like
  • 2 in conversation