求高手!!!有2个变量 怎么用sas或者R 建立一个只有1或者0 的二元矩阵
原始文件VAR1id_site447144724473447444854486想要建立成var1123456447111100448000011...
原始文件
VAR1 id_site
447 1
447 2
447 3
447 4
448 5
448 6
想要建立成
var1 1 2 3 4 5 6
447 1 1 1 1 0 0
448 0 0 0 0 1 1 展开
VAR1 id_site
447 1
447 2
447 3
447 4
448 5
448 6
想要建立成
var1 1 2 3 4 5 6
447 1 1 1 1 0 0
448 0 0 0 0 1 1 展开
1个回答
展开全部
/* bool */
data b;
set test;
a1=(id_site='1');
a2=(id_site='2');
a3=(id_site='3');
a4=(id_site='4');
a5=(id_site='5');
a6=(id_site='6');
run;
proc sql;
create table b2 as
select distinct var1,
sum(a1) as a1,
sum(a2) as a2,
sum(a3) as a3,
sum(a4) as a4,
sum(a5) as a5,
sum(a6) as a6
from b
group by var1;
quit;
data b;
set test;
a1=(id_site='1');
a2=(id_site='2');
a3=(id_site='3');
a4=(id_site='4');
a5=(id_site='5');
a6=(id_site='6');
run;
proc sql;
create table b2 as
select distinct var1,
sum(a1) as a1,
sum(a2) as a2,
sum(a3) as a3,
sum(a4) as a4,
sum(a5) as a5,
sum(a6) as a6
from b
group by var1;
quit;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询