|
|
5#

楼主 |
发表于 2009-7-17 23:23:57
|
只看该作者
Re: 请教读取特定格式的txt文本
我记的CMD是可以直接退出的,但忘了语句怎么写了,谁知道请告诉我,谢谢了.
[code:1c0j0nn2]%let dirpath=%nrstr(d:\);
x "cd &dirpath";
x "dir :attrib *.txt /o:-d/b >txt_name.txt";
data txt_name;
infile "&dirpath.txt_name.txt" firstobs=2;
input txt_name $;
txt_name=scan(txt_name,1,'.');
run;
%macro creatds(fname);
data &fname(label='体重表');
infile "&dirpath&fname..txt" end=end;
input sign $;
if sign='&p' then input bm=$10. /year=$4. /name=$20. /weight=8. /age=8. /_00 $5.;
else if end then stop;
else input name=$20. /weight=8. /age=8. /_00 $5.;
_00=substr(_00,4);
retain year;
drop sign bm;
run;
%mend;
%macro setds(fname,index);
data finalds;
%if &index=1 %then %do;
set &fname;
%end;
%else %do;
set finalds &fname;
%end;
run;
%mend;
data _null_;
set txt_name;
call execute('%creatds('||txt_name||')');
run;
data _null_;
set txt_name;
call execute('%setds('||txt_name||','||_n_||')');
run;[/code:1c0j0nn2] |
|