全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
3756 9
2013-08-01
悬赏 1888 个论坛币 已解决
medline.txt
大小:(116.96 KB)

 马上下载



附件为我在pubmed下载的medline结果,为37篇英文文章(我们这里称作记录),文件中以"PMID-"隔开的为一个记录
我要生成一个SAS数据集,每个记录(即文章)为一个观测,其中的变量需要包含以下几个:PMID;TI;AB;MH。其它的可有可无。
这四个东西分别代表我文章的id, title, abstract 和 mesh terms,其中变量的值是短杠“-”后面的文字,当然,有些文字可能跨行。

另外,MH可能有多个,我需要将所有的MH合并成一个变量

如何有效地利用infile, input进行导入,望高手指点

非常感谢,些许论坛币,聊表寸心
复制代码



二维码

扫码加我 拉你入群

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

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

全部回复
2013-8-1 21:37:52
复制代码
二维码

扫码加我 拉你入群

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

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

2013-8-1 22:13:18
楼主明显过虑了,没那么复杂
复制代码
二维码

扫码加我 拉你入群

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

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

2013-8-1 23:05:46
可以考虑下用这个,程序中有些变量的长度可能需要调整,但你说的功能基本能够实现

filename medline "C:\medline.txt";
/*read the file*/
data a;
infile medline truncover;
informat raw $200.;
input raw;
raw = _infile_;
N = _n_;
run;
data b;
set a;
/*processing for PMID*/
informat pmid $30.;
retain PMID ;
if index(upcase(raw),'PMID-') then PMID = scan(raw,2,'-');
/*processing for description, may need to update the length of desc*/
informat desc $5000.;
retain desc " " flag1 0;
if index(upcase(raw),'AB  -') then do;
  desc = substr(raw,7);
  flag1 = 1;
end;
if index(upcase(raw),'AD  -') then flag1=0;
if desc ne " " and substr(raw,1,6)='      ' and flag1=1 then  desc = strip(desc)||' '||strip(raw);
/*processing for TI*/
informat ti $500.;
retain ti " " flag2 0;
if index(upcase(raw),'TI  -') then do;
  TI = substr(raw,7);
  flag2 = 1;
end;
if index(upcase(raw),'AB  -') then flag2 = 0;
if ti ne " " and substr(raw,1,6)='      ' and flag2=1 then  ti = strip(ti)||' '||strip(raw);
/*processing for MH*/
/* the split character is |, you can change the one that you want*/
informat mh $500.;
retain mh " " flag3 0;
if index(upcase(raw),'SB  -') then do;
  mh = "Flag";
  flag3 = 1;
end;
if index(upcase(raw),'EDAT-') then flag3 = 0;
if mh ne " " and flag3=1 and index(raw,'MH  -') then mh = strip(mh)||'|'||strip(substr(raw,7));

run;
proc sort data = b(where=(pmid ne ' '));
by pmid n;
run;
data c;
set b;
by pmid n;
if last.pmid;
mh = substr(mh,6);
keep pmid desc mh ti;
run;

二维码

扫码加我 拉你入群

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

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

2013-8-2 21:28:44
呵呵,想起3年前,2010年左右写的一个89行的代码专门处理这个问题,现在一看,真是弱暴了啊。
二维码

扫码加我 拉你入群

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

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

2013-8-2 21:37:13
学习了。收藏下。以备不时之需,谢谢各位
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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