全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1664 9
2013-04-22
悬赏 30 个论坛币 已解决
以下患者信息,

caseID相同的人,做如下处理:
1、每个患者最后只保留一条汇总记录
2、有身份证号者,根据首次入院日期(Entdat)减去身份证号提取整数来得到最终的发病入院年龄(Entage),没有身份证号但记录有年龄的,以自报的年龄(age)作为入院年龄。注意:老的身份证号(如caseID=100890)与新的身份证的区别,对于caseID=100890,年份补充完全后出生日期应为1955-02-16
3、Pid和TNM信息以未缺失的信息作为患者汇总的Pid.

caseIDnameagePidTNMEntdat

100194

ZTJ

61

.T1N0M0

2010-1-19

100194

ZTJ

61

120104195009182922

2010-6-28

100196

YZX.12010519510913422XT2N1M0

2010-8-12

100878

YLY

50

.T3N1M0

2009-2-1

100890

DML.120109550216302T2N1M1

2009-8-18



最终整理的结果因为
caseIDnameEntagePidTNM

100194

ZTJ

60

120104195009182922T1N0M0

100196

YZX

59

12010519510913422XT2N1M0

100878

YLY

50

.T3N1M0

100890

DML

54

120109550216302T2N1M1


推荐用SQL,同时欢迎其他精彩的算法,谢谢啦!


最佳答案

qinly10 查看完整内容

两个方法: data have; infile cards missover; input id $ name $ age pid :$18. tnm $ entdat yymmdd10.; format entdat yymmdd10.; cards; 100194 ZTJ 61 . T1N0M0 2010-1-19 100194 ZTJ 61 120104195009182922 . 2010-6-12 100196 YZX . 12010519510913422X T2N1M0 2010-6-28 100878 YLY 50 . T3N1M0 2009-2-1 100890 DML . 120109550216302 T2N1M1 2009-8-18 ; run; proc sort data=have; by id entdat; run; ...
二维码

扫码加我 拉你入群

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

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

全部回复
2013-4-22 11:38:41
两个方法:
data have;
infile cards missover;
input id $ name $ age pid :$18. tnm $ entdat yymmdd10.;
format entdat yymmdd10.;
cards;
100194 ZTJ 61 . T1N0M0 2010-1-19
100194 ZTJ 61 120104195009182922 . 2010-6-12
100196 YZX . 12010519510913422X T2N1M0 2010-6-28
100878 YLY 50 . T3N1M0 2009-2-1
100890 DML . 120109550216302 T2N1M1 2009-8-18
;
run;
proc sort data=have;
by id entdat;
run;
/*方法1*/
data have1(keep=id pid);
set have;
where pid ne ' ';
run;
data have2;
set have;
by id;
if first.id;
run;
data want;
update have2 have1;
by id;
if pid ne ' ' then do;
  if length(pid)< 18 then age=year(entdat)-input('19'||substr(pid,7,2),4.);
  else age=year(entdat)-put(substr(pid,7,4),4.);
end;
run;
proc print;
run;
/*方法2*/
proc sql;
create table have3 as select id, name, age, max(pid) as  pid,
max(tnm) as tnm,entdat
from have
group by id;
quit;

data want;
set have3;
by id;
if first.id;
if pid ne ' ' then do;
  if length(pid)< 18 then age=year(entdat)-input('19'||substr(pid,7,2),4.);
  else age=year(entdat)-put(substr(pid,7,4),4.);
end;
run;
proc print;run;
二维码

扫码加我 拉你入群

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

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

2013-4-22 11:40:28
数据库  不懂         
二维码

扫码加我 拉你入群

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

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

2013-4-22 16:24:24
个人思路,subset出身份证号码PID 来得到Entage,可以区分15位还是18位的不同算法得到age
pro sql把新的dataset join回source,
keep TNM不为空的数据,
如果Entage不为空,age=Entage;如果Entage为空,Entage=age
drop age; proc sort, 保留不重复的应该就是想要的结果了
二维码

扫码加我 拉你入群

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

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

2013-4-22 16:46:53
PROC IMPORT OUT= WORK.mingyue
            DATAFILE= "D:\mingyue.xls"
            DBMS=EXCEL REPLACE;
       GETNAMES=YES;
     MIXED=NO;
     SCANTEXT=YES;
     USEDATE=YES;
     SCANTIME=YES;
RUN;
data mingyue;
set mingyue;
if length(pid)=15 then do;
part1=substr(pid,1,6);
part2=substr(pid,length(pid)-8,9);
newpid=compress(part1||'19'||part2||'X');
end;
if length(pid)=18 then newpid=pid;
birth=input(compress(substr(newpid,7,8)),yymmdd11.);
format birth yymmdd10.;
if pid ne '.' then entage=int(yrdif(birth,entdat,act/act));
if pid='.' then entage=age;
run;
proc sql;
create table newtable as select  distinct caseid, name,entage,   max(PID) as pid,  max(TNM) as TNM from mingyue
group by caseid;
quit;
二维码

扫码加我 拉你入群

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

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

2013-4-22 18:43:07
slimdell 发表于 2013-4-22 16:24
个人思路,subset出身份证号码PID 来得到Entage,可以区分15位还是18位的不同算法得到age
pro sql把新的dat ...
如果可以的话,希望能写出完整的语句,非常感谢,^_^
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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