Thank you for sharing the coalesce function - this worked perfectly. I used this to construct a macro as I wanted to repeat this with a series of variables (code below for anyone interested). Thank you! %Macro lastvar(var); data mvrx19.master; set mvrx19.master; last_&Var=coalesce(&var._20,&var._15,&var._10,&var._5,&var._1); run; %mend lastvar; %lastvar(PSSNS); %lastvar(PSS10NS); %lastvar(PSS4NS); %lastvar(dietfruit); %lastvar(dietvet); %lastvar(FI); %Macro Charlastvar(var); data mvrx19.master; set mvrx19.master; last_&Var=coalescec(&var._20,&var._15,&var._10,&var._5,&var._1); run;%mend Charlastvar; %Charlastvar(Physhealth); %Charlastvar(MFA);
... View more