This is down to the value I hardcoded in this row: 603 array elements{7,2} $20; Basically I am assuming there will be no more than 7 distinct elements in the string, this is just the test data I have at the time. Set it to elements{20,2} and that should cover it. I does however illustrate neatly why Reeza's answer is the better of the two. If you normalise your data: ROW DX 1 5849 1 42822 ... 2 41071 ... Then you can very easily run a freq/means procedure, or some simple code to get your result: proc sq; create table WANT as select ROW, DX, count(DX) as RESULT from HAVE group by ROW, DX; quit; Now to get the normalised data you can just do: data inter (keep=row dx); set have; i=1; do until (scan(dxcombine,i,' ') = ''); row=_n_; dx=scan(dxcombine,i,' '); output; i=i+1; end; run; This outputs one row per scanned word.
... View more