This should work for any reasonable number of variables with names that arent too long for it to work properly. data variables; input sales expenses employees ; cards; 200 100 2 300 200 3 400 220 4 ;;;; run; %let vars=Sales-numeric-employees; proc transpose data=variables(obs=0) out=names; var &vars; run; proc sql noprint; select _name_ into :vars separated by ' ' from names; quit; run; data names; length vname $32; set names; do vname = _name_,cats('T1',_name_),cats('T2',_name_); output; end; retain n 0; run; proc transpose data=names out=arrays(drop=_name_); var n; id vname; run; data want; if 0 then set arrays; Array _v &vars; Array _t1 t1:; Array _t2 t2:; set variables; Do i=1 to dim(_v); _t1= _v/lag(_v)-1; _t2= lag(_t1); end; Drop i; Run; proc contents varnum; proc print; run; # Variable Type Len 1 sales Num 8 2 T1sales Num 8 3 T2sales Num 8 4 expenses Num 8 5 T1expenses Num 8 6 T2expenses Num 8 7 employees Num 8 8 T1employees Num 8 9 T2employees Num 8 Obs sales T1sales T2sales expenses T1expenses T2expenses employees T1employees T2employees 1 200 . . 100 . . 2 . . 2 300 0.50000 . 200 1.0 . 3 0.50000 . 3 400 0.33333 0.5 220 0.1 1 4 0.33333 0.5
... View more