请选择 进入手机版 | 继续访问电脑版
楼主: tangliang0905
2298 4

array问题求解 [推广有奖]

  • 1关注
  • 3粉丝

讲师

52%

还不是VIP/贵宾

-

威望
0
论坛币
1167 个
通用积分
1.0083
学术水平
13 点
热心指数
20 点
信用等级
11 点
经验
30311 点
帖子
212
精华
0
在线时间
834 小时
注册时间
2012-11-29
最后登录
2018-12-11

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
我碰到一个问题,

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的情况,不知道应该如何改动啊,多谢多谢
二维码

扫码加我 拉你入群

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

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

关键词:array 问题求解 ARR Ray Input

回帖推荐

忍冬的秋 发表于4楼  查看完整内容

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 then abc=1 ; end; end; do m=1 to 7; if missing(abc[m]) = 1 then abc[m]=0; end; run;
teqel 发表于 2015-8-29 04:39:42 |显示全部楼层 |坛友微信交流群
  1. data a;
  2. input col1$ col2$  col3 $;
  3. cards;
  4. a b c
  5. c d e
  6. a b f
  7. a d g
  8. ;

  9. data b(drop=i);
  10. set a;
  11. array temp col1-col3;
  12. DO I = 1 TO 3;
  13. select(temp[I]);
  14.         when ('a') d1=1;
  15.         when ('b') d2=1;
  16.         when ('c') d3=1;
  17.         when ('d') d4=1;
  18.         when ('e') d5=1;
  19.         when ('f') d6=1;
  20.         when ('g') d7=1;
  21. end;
  22. end;
  23. run;
复制代码
已有 1 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
tangliang0905 + 5 + 3 + 3 + 3 精彩帖子

总评分: 论坛币 + 5  学术水平 + 3  热心指数 + 3  信用等级 + 3   查看全部评分

使用道具

多谢多谢,

如果推广到更普遍的情况,有可能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
;

使用道具

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;

使用道具

wh7064rg 发表于 2015-9-3 00:09:44 |显示全部楼层 |坛友微信交流群
teqel 发表于 2015-8-29 04:39
学习了

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-19 09:19