Thank you very much for your input. I wanted to spend some time digesting your syntax. It definitely appears to get the job done! Since I need to run this code on several different sets of columns, I incorporated a macro. data _null_;
do until(eof);
set sasdata.dataset end=eof;
num_coi_vars=max(num_coi_vars,n(of co_investigator_s___:));
num_res_vars=max(num_res_vars,n(of co_i_residents___:));
end;
call symputx('coi_col_total',num_coi_vars);
call symputx('res_col_total',num_res_vars);
run;
%macro array(prefix, array_name_old_vars, array_name_new_vars, column_count_macro);
%let prefix = &prefix;
drop &prefix: data_count index;
array &array_name_old_vars &prefix:;
array &array_name_new_vars [&column_count_macro];
data_count = 0;
do index=1 to dim(&array_name_old_vars);
if &array_name_old_vars[index] then do;
data_count + 1;
&array_name_new_vars[data_count] = input(substr(vname(&array_name_old_vars[index]),%length(&prefix)+1),32.);
end;
end;
%mend;
data want;
set sasdata.dataset;
%array(co_investigator_s___, OLD_coi, co_i, &coi_col_total);
%array(co_i_residents___, OLD_res, res, &res_col_total);
run; One additional step that would be helpful is to figure out a way to allow the array that creates the new variables, to only create the number of new variables that matches the maximum count variable. Right now, the array creates new variables to match the number calculated in the symput macro. I then need to run a frequency to see which variables have no data so I can remove those columns from the dataset. Any suggestions? @Tom proc freq data = want;
table co_i: res:;
run;
data want1;
set want;
drop co_pi8-co_pi&coi_col_total res5-res&res_col_total;
run;
... View more