I have the following data structure
ID Med1_1-Med1_5 Med_oth1 Med2_1-Med2_5 Med_oth2 Med3_1-Med3_5 Med_oth3 .... Med20_1-Med20_5 Med_oth20
I need to do the same thing to the variable in each group of 6 variables "MedX_1-MedX_5 Med_othX" . Basically find the one that is not null and assign that to a new variable.
I have done this before and I cannot find my example. The following is my attempt to do this with a macro and it is not working. Any help would be much appreciated
%macro Choose_med;
%do i = 1 %to 20;
%if Med&i._1 = 1 %then Med&i = Med_Ot&i ;
%else %if Med&i._1 ^= 1 or Med&i._1=. %then %do j = 1 %to 5;
%if Med&i._&j ^= 1 and Med&i._1^=. and Med&i="" %then Med&i = Med&i._j ;
%end;
%end;
%mend Choose_med;
Data Meds2;
set meds;
format Med1-med20 $100.;
%Choose_med;
run;