“Along the same line of thinking is it also possible to determine the length of the longest "word" in the array so I can efficiently set the length of the variables?”
I understand your question. But that is not so easy to get it.
Here is how to get the length of longest word:
data have;
input ID HCPCS_CD $50. ;
cards;
1 ["J3490", "J3590", "AAAXT"]
2 ["A990", "B210"]
3 ["C220", "B210", "J3490", "J3590"]
;
*Get the max number of columns in HCPCS_CD;
proc sql noprint;
select max(countw(HCPCS_CD,',"[] ','q')) into :max trimmed from have;
quit;
*Get the length of the longest word;
data _null_;
set have end=last;
retain length .;
do i=1 to countw(HCPCS_CD,',"[] ','q');
length=max(length,length(dequote(scan(HCPCS_CD,i,',"[] ','q'))));
end;
if last then call symputx('length',length);
run;
%put &=length.;
data want;
set have;
array x{*} $ &length. HCPCS_CD1-HCPCS_CD&max. ;
do i=1 to countw(HCPCS_CD,',"[] ','q');
x{i}=dequote(scan(HCPCS_CD,i,',"[] ','q'));
end;
drop i;
run;
... View more