A hash-transpose. Not so elegant; way too many hard-coding of variables! Also, dates were handled as character to simplify matters. The hash variables could have been handled with macro variables, through a prior Proc SQL. data _null_; if(1=2)then set have; length var1_200101-var1_200105 var2_200101-var2_200105 $2 ; declare hash varmon (ordered:"a"); varmon.defineKey("id"); varmon.defineData ("id","Var1_200101","Var1_200102","Var1_200103","Var1_200104","Var1_200105", "Var2_200101","Var2_200102","Var2_200103","Var2_200104","Var2_200105"); varmon.defineDone(); call missing (of _all_); array w{5,2} $ _temporary_; do until(done); set have end=done; rcf=varmon.find(key:id); w(1,1)=Var1_200101;w(2,1)=Var1_200102;w(3,1)=Var1_200103;w(4,1)=Var1_200104;w(5,1)=Var1_200105; w(1,2)=Var2_200101;w(2,2)=Var2_200102;w(3,2)=Var2_200103;w(4,2)=Var2_200104;w(5,2)=Var2_200105; mx=whichc(month,"200101","200102","200103","200104","200105"); w(mx,1)=var1; w(mx,2)=var2; rcr=varmon.replace(key:id,data:id,data:w(1,1),data:w(2,1),data:w(3,1),data:w(4,1),data:w(5,1), data:w(1,2),data:w(2,2),data:w(3,2),data:w(4,2),data:w(5,2)); call missing(of _all_); end; varmon.output(dataset:"want"); stop; run;
... View more