全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
2442 4
2015-08-29
我碰到一个问题,

data a;
input col1 $ col2 $ col3 $;
cards;
a b c
c d e
a b f
a b f
;

虽然只有三列,但是a对应durg1, b 对应drug2, c 对应drug3,以此类推,最后想要知道里面共有几种不同的drug,各是什么
也就是下面数据样式

col1col2 col3d1d2d3d4d5d6d7
abc

1

1

1

0

0

0

0

abf

1

1

0

0

0

1

0

bfg

0

1

0

0

0

1

1

cde

0

0

1

1

1

0

0



我觉得是用array来做,但是

data a;
input col1 $ col2 $ col3 $;
cards;
a b c
c d e
a b f
a b f
;

data b;
set a;
array temp col1-col3;
DO I = 1 TO 3;
d1=ifn(temp[I]='a',1,0);
d2=ifn(temp[I]='b',1,0);
d3=ifn(temp[I]='c',1,0);
d4=ifn(temp[I]='d',1,0);
d5=ifn(temp[I]='e',1,0);
d6=ifn(temp[I]='f',1,0);
d7=ifn(temp[I]='g',1,0);
end;
run;



这样却只有记录下最后一步col3的情况,不知道应该如何改动啊,多谢多谢
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2015-8-29 04:39:42
复制代码
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-8-29 06:09:17
多谢多谢,

如果推广到更普遍的情况,有可能col里面的值从 a 到 z,那也就要从d1手动写到d26,或者有可能会变成aa (27), ab (28),手写的话比较麻烦。

比如

data a;
input col1 $ col2 $ col3 $;
cards;
a b z
c d w
a b x
a b y
;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-2 15:24:44
data a;
input col1 $ col2 $ col3 $;
cards;
a b c
c d e
a b f
a e f
;
run;
data b(drop=i j m);
set a;
array abc{*} d1-d7;
array nn{*} col1-col3;
array mm{7} $ _temporary_ ('a','b','c','d','e','f','g');
do j=1 to 3;
do i=1 to 7;
if nn[j] = mm[i] then abc[i]=1 ;
end;

end;

do m=1 to 7;
if missing(abc[m]) = 1 then abc[m]=0;
end;
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-3 00:09:44
teqel 发表于 2015-8-29 04:39
学习了
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群