楼主: moonstone
1722 9

患者多条信息汇总相关问题(2) [推广有奖]

已卖:1872份资源

讲师

74%

还不是VIP/贵宾

-

威望
0
论坛币
10498 个
通用积分
369.2883
学术水平
160 点
热心指数
169 点
信用等级
124 点
经验
274346 点
帖子
237
精华
1
在线时间
520 小时
注册时间
2007-4-27
最后登录
2024-12-6

楼主
moonstone 发表于 2013-4-22 11:38:40 |AI写论文
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; ...
关键词:Case 身份证号 name 出生日期 身份证 数据 信息 表格

沙发
qinly10 发表于 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;

藤椅
D_MoMo 发表于 2013-4-22 11:40:28
数据库  不懂         
花开堪折直须折,莫待无花空折枝!
回帖是一种美德!

板凳
slimdell 发表于 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;

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

7
moonstone 发表于 2013-4-22 18:44:30
钻石小五郎 发表于 2013-4-22 16:46
PROC IMPORT OUT= WORK.mingyue
            DATAFILE= "D:\mingyue.xls"
            DBMS=EXCEL REPL ...
该语句SQL之前,有两个小问题
1、
entage=int(yrdif(birth,entdat,act/act)
应修改为:
entage=int(yrdif(birth,entdat,'act/act'))
2、
if pid='.'
应修改为
if pid=.

修改后中间数据对了,但SQL得到的数据仍有一个重要的问题没有解决

8
钻石小五郎 发表于 2013-4-25 15:47:08
哪个问题没解决啊?

9
moonstone 发表于 2013-4-26 07:59:57
钻石小五郎 发表于 2013-4-25 15:47
哪个问题没解决啊?
看一下你跑出来的中间库,caseID=100194的患者,有两条记录,第一条只有自报的年龄60,没有身份证号,第二条记录根据身份证算出来的年龄为59,实际我想要的是第二条记录。但是最后合并的数据库对这个问题没有解决。你再认真看看。哈哈,非常感谢,^_^

10
钻石小五郎 发表于 2013-4-30 23:59:57
不好意思 中间加了一个变量标识了一下年龄的计算方式,代码如下,请楼主看一下。
PROC IMPORT OUT= WORK.mingyue
            DATAFILE= "D:\mingyue.xls"
            DBMS=EXCEL REPLACE;
       GETNAMES=YES;
     MIXED=NO;
     SCANTEXT=YES;
     USEDATE=YES;
     SCANTIME=YES;
RUN;
data mingyue1;
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 ne '.' then age_way=0;
if pid='.' then entage=age ;
if pid='.' then  age_way=1;
run;

proc sql;
create table newtable as select  distinct caseid, name,entage,   max(PID) as pid,  max(TNM) as TNM, age_way from mingyue1
group by caseid;
delete from newtable where pid ne '.' and age_way=1;
alter table newtable drop age_way;
quit;

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-8 22:38