楼主: nomad5
2866 12

求高手写代码 [推广有奖]

  • 0关注
  • 2粉丝

硕士生

0%

还不是VIP/贵宾

-

威望
0
论坛币
94 个
通用积分
1.0000
学术水平
13 点
热心指数
13 点
信用等级
11 点
经验
1898 点
帖子
90
精华
0
在线时间
114 小时
注册时间
2010-12-18
最后登录
2022-5-2

楼主
nomad5 发表于 2011-7-3 01:29:56 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
求高手写代码,附件是数据集。

要求:FLAG= "Yes" , in the following  cases:
   
(1) TYPE="Vomiting"  ;
   
(2) TYPE="Retching",  and its duration >= 5 minutes ;
   
(3) TYPE="Retching",  and it is preceded or followed by a "Vomiting", and the time  between "Retching" and "Vomiting" <= 1 minute ;
   
(4) TYPE="Retching",  and it is preceded or followed by other "Retching" events, and  Ending time of the last event - Beginning time of the first event >= 5  minutes, and the time between any two events <= 1 minute ;
   
我实在是写不出来了,看过别人写的代码,没看懂,怎么看怎么像是错的。由于是真实的数据,所有要求中的(1)(2)两条就把所有的FLAG都置成yes了,无法根据结果判断(3)(4)是否正确。
所以恳求各位高手有时间的话帮我看看。
二维码

扫码加我 拉你入群

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

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

关键词:求高手 following Duration Between Minutes SAS

demo.rar
下载链接: https://bbs.pinggu.org/a-931381.html

1 KB

本附件包括:

  • demo.sas7bdat

已有 1 人评分经验 论坛币 收起 理由
liuzhenzhu + 10 + 3 鼓励积极发帖讨论

总评分: 经验 + 10  论坛币 + 3   查看全部评分

本帖被以下文库推荐

沙发
yugao1986 发表于 2011-7-3 10:15:09
lz可以把看到的代码贴出来吗?
三人行必有我师

藤椅
nomad5 发表于 2011-7-3 18:24:46
这是整篇代码中关于要求的一部分,单独执行这一部分得出的结果和整篇代码得出的结果不一样,但是只有这一部分是符合要求的。

data demo ;  set demo ;  by id stdt descending endt descending type ;

length flag $3 ;  label flag="Emetic episode? (Yes/No)" ;

length pr_type pr1_type pr2_type pr3_type pr4_type pr5_type $8 ;

retain pr_endt pr_stdt pr_type pr1_endt pr1_stdt pr1_type pr2_endt pr2_stdt pr2_type pr3_endt pr3_stdt pr3_type pr4_endt pr4_stdt pr4_type pr5_endt pr5_stdt pr5_type ;

*format pr_endt pr_stdt pr1_endt pr1_stdt pr2_endt pr2_stdt  pr3_endt pr3_stdt pr4_endt pr4_stdt pr5_endt pr5_stdt datetime20.0 ;

if first.id then do ;  
pr_endt=. ;   pr_stdt=. ;   pr_type="" ;   pr1_endt=. ;  pr1_stdt=. ;  pr1_type="" ;
pr2_endt=. ;  pr2_stdt=. ;  pr2_type="" ;  pr3_endt=. ;  pr3_stdt=. ;  pr3_type="" ;
pr4_endt=. ;  pr4_stdt=. ;  pr4_type="" ;  pr5_endt=. ;  pr5_stdt=. ;  pr5_type="" ;
end ;

if stdt>pr1_stdt>. then do ; dif_flag=1 ;  end ;

if type="Vomiting" then flag="Yes" ;
    if type="Retching" then do ;
        if endt-stdt>=60*5 then flag="Yes" ;
        else if pr_type="Vomiting" and .<stdt-pr_endt<=60 then flag="Yes" ;
        else if  .<stdt-pr1_endt<=60 then do ;
            if pr1_type="Retching" then do ;
                if endt-pr1_stdt>=60*5 then flag="Yes" ; else do ;
                    if .<pr1_stdt-pr2_endt<=60 then do ;
                        if pr2_type="Retching" then do ;
                            if endt-pr2_stdt>=60*5 then flag="Yes" ; else do ;
                                if .<pr2_stdt-pr3_endt<=60 then do ;
                                    if pr3_type="Retching" then do ;
                                        if endt-pr3_stdt>=60*5 then flag="Yes" ; else do ;
                                            if .<pr3_stdt-pr4_endt<=60 then do ;
                                                if pr4_type="Retching" then do ;
                                                    if endt-pr4_stdt>=60*5 then flag="Yes" ; else do ;
                                                        if .<pr4_stdt-pr5_endt<=60 then do ;
                                                            if pr5_type="Retching" then do ;
                                                                if endt-pr5_stdt>=60*5 then flag="Yes" ;
                                                            end ;
                                                        end ;
                                                    end ;
                                                end ;
                                            end ;
                                        end ;
                                    end ;
                                end ;
                            end ;
                       end ;
                   end ;
               end ;
           end ;
       end ;
    end ;

pr_type=type ;  pr_stdt=stdt ;  pr_endt=endt ;

if first.id or dif_flag=1 then do ;
pr5_type=pr4_type ;  pr5_stdt=pr4_stdt ;  pr5_endt=pr4_endt ;
pr4_type=pr3_type ;  pr4_stdt=pr3_stdt ;  pr4_endt=pr3_endt ;
pr3_type=pr2_type ;  pr3_stdt=pr2_stdt ;  pr3_endt=pr2_endt ;
pr2_type=pr1_type ;  pr2_stdt=pr1_stdt ;  pr2_endt=pr1_endt ;
pr1_type=type ;   pr1_stdt=stdt ;   pr1_endt=endt ;
end ;

/*drop dif_flag pr: ;*/

run ;

板凳
honghejing 发表于 2011-7-5 11:08:55
这么多end?看得头晕。。。

报纸
SAS程序员 发表于 2011-7-5 11:58:25
头晕!!!!!

地板
nomad5 发表于 2011-7-5 12:01:31
我已经头晕了好多天了

7
nomad5 发表于 2011-7-5 12:11:51
重新编辑了一下 谁帮我看看啊

8
coolsky2004 发表于 2011-7-7 22:41:42
/**************** begin*****************/
求高手写代码,附件是数据集。

要求:FLAG= "Yes" , in the following  cases:
   
(1) TYPE="Vomiting"  ;
   
(2) TYPE="Retching",  and its duration >= 5 minutes ;
   
(3) TYPE="Retching",  and it is preceded or followed by a "Vomiting", and the time  between "Retching" and "Vomiting" <= 1 minute ;
  可以对此进行分解: R and (lagR is V or leadR is V) and duration<=1  等于 R and lagR is V    or R and leadR is V   and abs(dif(duration))<=1
   
(4) TYPE="Retching",  and it is preceded or followed by other "Retching" events,
             and  Ending time of the last event - Beginning time of the first event >= 5  minutes,
             and the time between any two events <= 1 minute ;



/**************** end*****************/

/**************** 代码开始*****************/
data aa; set sasuser.demo;duration=(endt-stdt)/60;run;
data bb; set aa;
   if  TYPE="Vomiting" then FLAG= "Yes";
   if  TYPE="Retching" and duration>=5
             then FLAG= "Yes";
   if  ((TYPE="Retching" and lag(TYPE)="Vomiting") or  (TYPE="Vomiting" and lag(TYPE)="Retching")) and         abs(dif(duration))<=1
             then FLAG= "Yes";
   if  (TYPE="Retching" and lag(TYPE)="Retching") ) and (endt-lag(stdt))/60>=5 and          abs(dif(duration))<=1
             then FLAG= "Yes";

run;

9
coolsky2004 发表于 2011-7-7 22:54:32
将上面的数据集以excel的形式附上。
ID        STDT        ENDT        TYPE        duration        
33798        05APR2010:23:00:00        05APR2010:23:05:00        Retching        5        
33798        06APR2010:01:30:00        06APR2010:01:35:00        Retching        5        
33798        06APR2010:09:15:00        06APR2010:09:20:00        Retching        5        
33798        07APR2010:06:30:00        07APR2010:06:40:00        Retching        10        
33798        07APR2010:08:30:00        07APR2010:08:45:00        Vomiting        15        
33798        07APR2010:08:30:00        07APR2010:08:45:00        Retching        15        
33798        07APR2010:11:00:00        07APR2010:11:05:00        Retching        5        
33798        07APR2010:14:30:00        07APR2010:14:35:00        Retching        5        
33798        08APR2010:06:30:00        08APR2010:06:35:00        Retching        5        
33798        08APR2010:14:30:00        08APR2010:14:40:00        Vomiting        10        
33798        08APR2010:14:30:00        08APR2010:14:40:00        Retching        10      
33798        09APR2010:07:30:00        09APR2010:07:40:00        Retching        10        
33798        09APR2010:16:00:00        09APR2010:16:05:00        Retching        5        
34018        05APR2010:13:40:00        05APR2010:13:42:00        Vomiting        2        
34018        05APR2010:17:30:00        05APR2010:17:32:00        Vomiting        2        
34018        05APR2010:19:01:00        05APR2010:19:03:00        Vomiting        2        
34018        06APR2010:14:25:00        06APR2010:14:27:00        Vomiting        2        
34018        06APR2010:18:40:00        06APR2010:18:42:00        Vomiting        2        
34018        06APR2010:20:05:00        06APR2010:20:07:00        Vomiting        2        
34018        07APR2010:10:35:00        07APR2010:10:38:00        Vomiting        3        
34018        07APR2010:13:05:00        07APR2010:13:08:00        Vomiting        3        
34018        08APR2010:10:30:00        08APR2010:10:32:00        Vomiting        2        
65397        07JUL2010:21:00:00        07JUL2010:21:05:00        Vomiting        5        
65397        10JUL2010:20:45:00        10JUL2010:20:50:00        Vomiting        5        
91184        14AUG2010:22:30:00        14AUG2010:22:35:00        Vomiting        5        
142715        10OCT2010:05:00:00        10OCT2010:05:10:00        Retching        10        
142715        11OCT2010:05:00:00        11OCT2010:05:40:00        Retching        40        
142715        12OCT2010:05:00:00        12OCT2010:05:05:00        Vomiting        5        
142715        12OCT2010:10:00:00        12OCT2010:10:30:00        Retching        30        
147547        20OCT2010:08:00:00        20OCT2010:08:15:00        Vomiting        15        
148906        07NOV2010:03:00:00        07NOV2010:03:10:00        Vomiting        10        
148906        07NOV2010:03:00:00        07NOV2010:03:10:00        Retching        10        
148906        07NOV2010:09:40:00        07NOV2010:10:00:00        Retching        20        
148906        07NOV2010:11:30:00        07NOV2010:11:50:00        Retching        20        
149058        23OCT2010:16:30:00        23OCT2010:22:00:00        Vomiting        330

10
nomad5 发表于 2011-7-10 00:35:45
谢谢coolsky2004肯花费时间写
有一个问题,每一个ID是一个实例,所以应该按ID分组,这个怎么加上去。

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-30 08:24