SAS列的堆叠

注: "SUV"n 指定包含SAS通常限制的字符变量名。当外部导入的变量不符合SAS命名规则时可以使用。

data cars;
set sashelp.cars; rename type=ntype; keep make ntype MPG_City; run; proc sort data=cars nodup; by make ntype; run; data cars; retain a; set cars; by make ntype; if first.ntype then a=MPG_City; else a=a+MPG_City; if last.ntype; drop MPG_City; rename a= MPG_City; run; proc transpose data=cars out=t_cars; by make; var MPG_City; id ntype; run; proc sort data=t_cars(keep= "SUV"n "Sedan"n "Sports"n "Wagon"n make) out=cars1; by make; run; proc sql; create view cars2 as select a.*,"ntype" as coloum from cars1 a; quit; proc transpose data=cars2 out=cars3; by make; id coloum; var "SUV"n "Sedan"n "Sports"n "Wagon"n; run;

posted @ 2019-12-31 10:50  虾米WD  阅读(194)  评论(0)    收藏  举报