楼主: baojiwolong
2092 5

[问答] 如何读入这样的文本(二) [推广有奖]

  • 0关注
  • 8粉丝

博士生

58%

还不是VIP/贵宾

-

威望
0
论坛币
471 个
通用积分
7.7500
学术水平
15 点
热心指数
32 点
信用等级
12 点
经验
7654 点
帖子
167
精华
0
在线时间
454 小时
注册时间
2007-2-1
最后登录
2024-9-23

楼主
baojiwolong 发表于 2010-12-1 21:15:20 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
读入这样的文本,第一行以“>”开始,读入为name,最后一行都以“//”结束,读入为sequence.
当这段文本总长度不超过32767时,hopewell提供的代码非常有效!
但当总长度超过约50000时,如何修改下面代码,使得第一行读入为name,文本第二行到“ORIGIN”读入为note,“ORIGIN”到“//”之间读入为sequence;
filename testdata 'd:\testdata.txt';
data raw;
    length name $10 sequence $10000;
    retain name sequence;
    infile testdata;
    input;
    if substr(_infile_,1,1)='>' then name=substr(_infile_,2);
    else if _infile_='//' then do;
        output;
        call missing(sequence);
    end;
    else sequence=cats(sequence,_infile_);
run;
二维码

扫码加我 拉你入群

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

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

关键词:sequence hopewell filename missing infile 文本

沙发
frackdeng 发表于 2010-12-1 23:32:15
  1. filename testdata 'd:\testdata.txt';
  2. data raw;
  3.     length name $10 temp note sequence $30000;
  4.     retain name temp note sequence;
  5.     infile testdata;
  6.     input;
  7.     if find(_infile_,'>')=1then name=substr(_infile_,2);
  8.     else if _infile_='ORIGIN' then do;
  9.         note=temp;
  10.         call missing(temp);
  11.     end;
  12.     else if _infile_='//' then do;
  13.         sequence=temp;
  14.         output;
  15.         call missing(temp);
  16.     end;
  17.     else temp=cats(temp,_infile_);
  18. run;
复制代码

藤椅
baojiwolong 发表于 2010-12-2 10:11:07
frackdeng 发表于 2010-12-1 23:32
  1. filename testdata 'd:\testdata.txt';
  2. data raw;
  3.     length name $10 temp note sequence $30000;
  4.     retain name temp note sequence;
  5.     infile testdata;
  6.     input;
  7.     if find(_infile_,'>')=1then name=substr(_infile_,2);
  8.     else if _infile_='ORIGIN' then do;
  9.         note=temp;
  10.         call missing(temp);
  11.     end;
  12.     else if _infile_='//' then do;
  13.         sequence=temp;
  14.         output;
  15.         call missing(temp);
  16.     end;
  17.     else temp=cats(temp,_infile_);
  18. run;
复制代码
还是有点问题,结果是tmp与sequecce结果一样,均为“ORIGIN”之后的文本,而note值缺失了!

板凳
frackdeng 发表于 2010-12-2 14:00:53
我运行没问题啊,temp是个过程变量,可以drop掉。
你加个proc print 放后面,看看部分data是什么样的。
3# baojiwolong

报纸
baojiwolong 发表于 2010-12-2 21:24:28
frackdeng 发表于 2010-12-2 14:00
我运行没问题啊,temp是个过程变量,可以drop掉。
你加个proc print 放后面,看看部分data是什么样的。
3# baojiwolong
谢谢,程序解决问题了,直接打开SAS数据集时确实看不到note!
不过proc print的时候note的值就出来!
再set raw后note后值就显示正常了,不知为何!
Anyway,thanks,frackdeng!

地板
frackdeng 发表于 2010-12-2 23:15:43
5# baojiwolong
共同提高,正好我也需要这方面的知识

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

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