You don't need to two passes through the data to calculate the maximum number of words and the maximum word length.
And note that double quotes should not be considered a delimiter.
*Get the max number of words and length of the longest word;
data _null_;
set have end=last;
retain length 1 max 1;
n=countw(HCPCS_CD,',[] ','q');
max=max(n,max);
do i=1 to n;
length=max(length,lengthn(dequote(scan(HCPCS_CD,i,',[] ','q'))));
end;
if last then do;
call symputx('length',length);
call symputx('max',max);
end;
run;
%put &=max &=length;
... View more