标题: 求助:变量的频数统计并以一定的形式输出 [打印本页] 作者: shiyiming 时间: 2011-2-24 10:37 标题: 求助:变量的频数统计并以一定的形式输出 我要将变量统计出来,并且以一定的形式输出,比如:
变量 x y
x 1 2 1 2 1 2 1 2
y 1 2 3 4 1 2 3 4
统计x=1和x=2的分别是多少,y= 1,2 ,3,4的分别有多少,并且以这种形式输出:
var count
x_1 4
x_2 4
y_1 2
y_2 2
y_3 2
y_4 2
变量和观测值都有上百个,哪位能高手指点一下吗?
谢谢啦。。。作者: shiyiming 时间: 2011-2-24 12:50 标题: Re: 求助:变量的频数统计并以一定的形式输出 [code:3lc3iprf]data had;
array x_[8] _temporary_ (1 2 1 2 1 2 1 2);
array y_[8] _temporary_ (1 2 3 4 1 2 3 4);
do i =1 to dim(x_);
x =x_[i]; y =y_[i]; output;
end;
run;
proc sql;
select cats('x_', x) as var, count(*) as count from had group by x
union all
select cats('y_', y) as var, count(*) as count from had group by y;
quit;[/code:3lc3iprf]作者: shiyiming 时间: 2011-2-24 13:15 标题: Re: 求助:变量的频数统计并以一定的形式输出 to jingju11
可是我的变量和观测值很多,变量差不多上百个,观测值也是上百个的那种。。。。作者: shiyiming 时间: 2011-2-25 10:14 标题: Re: 求助:变量的频数统计并以一定的形式输出 [code:17eubzos]data one(where=(num ne ' '));
input var1 $1. @@;
if missing(var1) = 0;
retain id;
if anyalpha(var1) ne 0 then do; id=var1; output;end;
else do; num=var1; output; end;
drop var1;
cards;
x 1 2 1 2 1 2 1 2
y 1 2 3 4 1 2 3 4
;
run;
proc sql;
create table two as
select cats(id, '_', num) as var format=$3., count(*) as count
from one
group id, num
;quit;
[/code:17eubzos]