This is how I would approach the problem identify the 29 variables that need to be kept track of
%let list_of_vars_to_track=<some varlist separated by spaces>;
%let list_of_vars_len_to_track=<some varlist separated by spaces>;
%macro test;
data FinalDataSet(rename=(
%do i = 1 %to 29;
ret_%scan(list_of_vars_to_track,&i.,%str( )) =%scan(list_of_vars_to_track,&i.,%str( ))
%end;
));
length %do i = 1 %to 29;
ret_%scan(list_of_vars_to_track,&i.,%str( )) %scan(list_of_vars_len_to_track,&i.,%str( ))
%end;;
set AC4 EP4 IP4 CD4;
by doctor;
retain %do i = 1 %to 29;
ret_%scan(list_of_vars_to_track,&i.,%str( ))
%end; ' ';
if first.doctor then do;
%do i = 1 %to 29;
ret_%scan(list_of_vars_to_track,&i.,%str( )) = '';
%end;
end;
%do i = 1 %to 29;
if not missing(%scan(list_of_vars_to_track,&i.,%str( ))) then
ret_%scan(list_of_vars_to_track,&i.,%str( )) =%scan(list_of_vars_to_track,&i.,%str( ));
%end;
if last.doctor then output;
drop %do i = 1 %to 29;
%scan(list_of_vars_to_track,&i.,%str( ))
%end; ;
run;
%mend test;
... View more