全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1507 5
2016-11-23
悬赏 20 个论坛币 已解决
复制代码

希望得到的数据集id  trt  tag
1   1    0
2   1    1
3   2    1
4   2    1

最佳答案

lovexialulu 查看完整内容

proc sql noprint; create table bbb as select distinct id,trt,count( case when x in (3 4) then id else . end) as tag from aaa group by id trt order by id trt; quit;
二维码

扫码加我 拉你入群

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

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

全部回复
2016-11-23 22:09:43

proc sql noprint;
        create table bbb as
select distinct id,trt,count( case when x in (3 4) then id else . end) as tag
from aaa group by id trt order by id trt;
quit;
二维码

扫码加我 拉你入群

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

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

2016-11-23 22:57:50
lovexialulu 发表于 2016-11-23 22:48
proc sql noprint;
        create table bbb as
select distinct id,trt,count( case when x in (3 4) ...
proc sql noprint;
        create table bbb as
select distinct id,trt,count( case when x in (3 4) then id else . end) as tag
from aaa group by id,trt order by id,trt;
quit;
程序缺了两个逗号。
但结果和我的要求不一样
二维码

扫码加我 拉你入群

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

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

2016-11-24 09:37:47
在楼上的基础上增加一步就可以了~
proc sql noprint;
        create table ccc as
        select distinct id ,trt,count(case when x in (3 4) then id else . end) as x1 from aaa
        group by id,trt;
quit;

data ddd;
        set ccc;
        if x1 = 0 then tag = 0;
        else tag = 1;
        drop x1;
run;
二维码

扫码加我 拉你入群

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

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

2016-11-24 10:49:48
复制代码
二维码

扫码加我 拉你入群

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

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

2016-11-24 14:33:30

data b;
        set aaa;
        by id;
        retain tag;
        if first.id then tag=0;
        if x in (3,4) then  tag=1;
        if last.id;
run;
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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