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

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

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

2 REPLIES 2
ballardw
Super User

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.

DME790
Pyrite | Level 9

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

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 46149 views
  • 5 likes
  • 2 in conversation