Hello Dear, Just simplified your code by macro . data have; input ID & Name & $ FirmID & A1981 & A1982 & B1981 & B1982 & C1981 & C1982 &; datalines; 1 x 123 2 3 4 5 6 7 2 y 124 22 33 44 55 66 77 3 z 555 222 333 444 555 666 777 ; run; %macro tran(out=,var_v=,pre_v=); proc transpose data=have out=&out (rename=(&var_v=&pre_v _name_=year)) prefix=&pre_v; by id name firmid; var &var_v:; run; %mend; /*Calling Macro*/ %tran(out=a_dataset,var_v=a1,pre_v=a); %tran(out=b_dataset,var_v=b1,pre_v=b); %tran(out=c_dataset,var_v=c1,pre_v=c); data want; merge a_dataset b_dataset c_dataset; by id name firmid; year=input(substr(year,2),8.); run;
... View more