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_DT | Calls | Trans1 | Calls2 | Trans2 | Calls3 | Trans3 | Calls4 | Trans4 | TRANS_CNT | CALLS |
18/02/2018 | 33411 | 5017 | 30738 | 4394 | 33431 | 5406 | 49582 | 8349 | 24454 | 155363 |
25/02/2018 | 32423 | 4491 | 30015 | 4499 | 38112 | 6159 | 46175 | 7849 | 24332 | 155993 |
04/03/2018 | 33981 | 4026 | 30184 | 3787 | 36763 | 6140 | 49303 | 7835 | 22884 | 160005 |
11/03/2018 | 32509 | 4197 | 29403 | 3220 | 36842 | 5540 | 45554 | 6780 | 20538 | 153633 |
Any help appreciated.
Dean
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.
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.
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
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!
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.