我想通过划分现有行来创建新列。 该表的代码如下:
DATA WORK.dataset;
INPUT Case1 Case2 Case3 Kat$;
datalines;
10 100 1000 A
2 2 2 B
;
我希望我的结果成为一个像这样的数据表:
CaseX1 CaseX2 CaseX3
5 50 500
所以我希望将一列除以另一列。
答案 0 :(得分:0)
一种解决方法可能是使用proc转置来处理列,然后使用SQL来完成如下操作:
DATA WORK.dataset;
INPUT Case1 Case2 Case3 Kat$;
datalines;
10 100 1000 A
2 2 2 B
;
/*Taking only numeric columns*/
data want_num(keep=_NUMERIC_) want_char(keep=_CHARACTER_);
set work.dataset;
run;
/*Transposing dataset */
proc transpose data=work.want_num out= work.dataset1(drop=_:);
run;
/*Calculating the division*/
proc sql;
create table work.dataset2 as
select col1/col2 as Case1X
from work.dataset1;
quit;
/*Transposing back*/
proc transpose data= work.dataset2 out= res(drop=_:) prefix=CaseX;
run;
干杯!