全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
2075 5
2010-01-29
例如我现在有一些数据想读入data
1232&12
dasf&
fdas1&asdf1&
我想读入的效果是按&分行
结果如下:
1232&
12dasf&
fdas1&
asdf1&
如何用sas读入?谢谢
二维码

扫码加我 拉你入群

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

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

全部回复
2010-1-29 23:54:14
hengda 发表于 2010-1-29 21:50
例如我现在有一些数据想读入data
1232&12
dasf&
fdas1&asdf1&
我想读入的效果是按&分行
结果如下:
1232&
12dasf&
fdas1&
asdf1&
如何用sas读入?谢谢
Hope this helps.

data t1;
retain y ' ';
infile cards;
input;
n=length(_infile_) - length(compress(_infile_,
'&'));
do i = 1 to n;
x=catt(y,scan(_infile_,i,
'&'),'&');
output;
end;
y=scan(_infile_,n+
1,'&');
drop y n i;
cards;
1232&12
dasf&
fdas1&asdf1&
;
proc print; run;
二维码

扫码加我 拉你入群

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

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

2010-1-30 13:08:00
谢谢,貌似第一行最后的2没读到;另外有没有不使用do end的循环而直接读入的?
二维码

扫码加我 拉你入群

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

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

2010-1-30 14:47:52
抄袭一下
data t1;
retain y ;
infile cards;
input;
n=length(_infile_) - length(compress(_infile_,'&'));
do i = 1 to n;
x=compress(catt(y,scan(_infile_,i,'&'),'&'),.);
output;
end;
y=scan(_infile_,n+1,'&');
cards;
1232&12
dasf&
fdas1&asdf1&
;
proc print; run;
二维码

扫码加我 拉你入群

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

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

2010-1-30 22:44:38
xiaosanmao 发表于 2010-1-30 14:47
抄袭一下
data t1;
retain y ;
infile cards;
input;
n=length(_infile_) - length(compress(_infile_,'&'));
do i = 1 to n;
x=compress(catt(y,scan(_infile_,i,'&'),'&'),.);
output;
end;
y=scan(_infile_,n+1,'&');
cards;
1232&12
dasf&
fdas1&asdf1&
;
proc print; run;
Change
retain y ;   -----> retain y ' ';

There is an important point here.
二维码

扫码加我 拉你入群

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

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

2010-1-30 23:07:14
bobguy 发表于 2010-1-30 22:44
xiaosanmao 发表于 2010-1-30 14:47
抄袭一下
data t1;
retain y ;
infile cards;
input;
n=length(_infile_) - length(compress(_infile_,'&'));
do i = 1 to n;
x=compress(catt(y,scan(_infile_,i,'&'),'&'),.);
output;
end;
y=scan(_infile_,n+1,'&');
cards;
1232&12
dasf&
fdas1&asdf1&
;
proc print; run;
Change
retain y ;   -----> retain y ' ';

There is an important point here.
But if you change like that,you can't get the right answer.
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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