SAS用空格替换换行符/回车

时间:2016-06-20 10:11:28

标签: sas carriage-return linefeed

我想读取一个文件并用空格替换所有换行符/回车符。你能帮忙吗?

/*input.txt*/
<li 
    data-linked-resource-type="userinfo" data-base-url="https://gbr.host.com/cc">Jean
    Paul  
    Gautier 
    </a></li>

/*Required output*/
<li data-linked-resource-type="userinfo" data-base-url="https://gbr.host.com/cc">Jean Paul Gautier</a></li>

/*sas datastep*/
data inp;
infile "c:/tmp/input.txt";
/*ADD LOGIC*/
infile "c:/tmp/output.txt";
run;

1 个答案:

答案 0 :(得分:1)

我建议您逐行阅读文本文件,然后将这些行连接在一起。

data inp;
length x $300. y $300.;
retain y "";
infile "d:/input.txt" dsd truncover;
input x $;
y=catx(" ",y, x); /*concat every line seperated by a space*/
run;

data _null_;
 set inp end=EOF ;
    FILE  'd:\input2.txt' ;     /* Output Text File */
    if eof ; /*only last observation has full concatinated string*/
    y=compbl(y); /*remove additional spaces*/
    PUT y; 
run;

否则您可以像我在上一个问题中向您展示的那样替换换行符:

tranwrd(mydata,'0A'x, " ");