SAS中文论坛

标题: 如何从大的数据库中选出一部分 [打印本页]

作者: shiyiming    时间: 2006-8-20 15:16
标题: 如何从大的数据库中选出一部分
我的数据是这样的
id operation_side date
1 left 01/03/2003
1 right 01/03/2003
2 left 02/09/2003
3 right 09/03/2003
4 left 02/04/2003
4 right 03/09/2003
...

我这个数据中有的病人是同一天左右膝盖都动了手术的(如病人1),有的病人是左右膝盖在不同天动的手术(如病人4),还有的是只有一个膝盖动了手术(如病人2和3);怎么才能把他们根据这三种类型分成三个数据库? 谢谢!
作者: shiyiming    时间: 2006-8-21 23:41
标题: RE:
[code:98de9]proc sort data=knee; by id; run;

data oneside keys(keep=id label);
  set knee;            
  by id;   
  if first.id and last.id then output oneside;  
  else do;                     
    if last.id and date=lag(date) then do;  
       label=1; output keys;
    end;   
    else if last.id then do;
      label=2; output keys;
    end;
  end;  
run;  
                  
data samedate diffdate;   
  merge knee keys;  
  by id;
  if label=1 then output samedate;      
  else if label=2 then output diffdate;
  drop label;                  
run;[/code:98de9]
作者: shiyiming    时间: 2006-8-22 08:39
标题: HOHO
楼上的程序,第一有语法错误,第二把语法错误改了结果也不对.
IF 的分割根本就不封闭.
作者: shiyiming    时间: 2006-8-22 10:32
标题: Ahuige
do you have any good idea to split the file? tks
作者: shiyiming    时间: 2006-8-22 14:59
标题: hoho
Too simple, without any challenge.
No taste at all. <!-- s:roll: --><img src="{SMILIES_PATH}/icon_rolleyes.gif" alt=":roll:" title="Rolling Eyes" /><!-- s:roll: -->
作者: shiyiming    时间: 2006-8-22 18:27
标题: 简单也要帮阿
即使简单,也要帮忙啊,怎么能过于简单就不管呢,我向每个人都经历过这样的时候吧!
作者: shiyiming    时间: 2006-8-22 23:21
标题: RE:
There are both logical and syntx errors in the sample code.  <!-- s:oops: --><img src="{SMILIES_PATH}/icon_redface.gif" alt=":oops:" title="Embarassed" /><!-- s:oops: -->
Check out the revised code above #2.
[quote:ac0fc]Too simple, without any challenge.
No taste at all.[/quote:ac0fc]
It is better to share your GOOD idea and kindly help others.  Here is not just for the challenge and competition. <!-- s8) --><img src="{SMILIES_PATH}/icon_cool.gif" alt="8)" title="Cool" /><!-- s8) -->
We'd like to see your sample or hint in the simpler and more efficient way.    Thx.
作者: shiyiming    时间: 2006-8-23 09:34
标题: 我手持钢鞭将你打.
[code:5f279]proc sort ;
  by id date;
run;

data oneside samedate diffdate;
  set ahuige;drop flag;
  by id date;
  flag=first&#46;id+last&#46;id+first&#46;date+last&#46;date;
  if flag =4 then output oneside;
  if flag =2 then output samedate;
  if flag =3 then output diffdate;
run;[/code:5f279]
不知道为了什么,忧愁它围绕着我.........................
作者: shiyiming    时间: 2006-8-23 10:20
标题: many thanks
Hi Ahuige and SAS_FAN,

many thanks to both of you. I am just new comer and very appreciate your patient.
作者: shiyiming    时间: 2006-8-23 21:51
标题: ahuige's contribution
[quote:a8827]flag=first.id+last.id+first.date+last.date;[/quote:a8827]
<!-- s:o --><img src="{SMILIES_PATH}/icon_surprised.gif" alt=":o" title="Surprised" /><!-- s:o -->  it is realy good trick and is rare to see this way for grouping.




欢迎光临 SAS中文论坛 (http://mysas.net/forum/) Powered by Discuz! X3.2