Search code examples
sascarriage-returnlinefeed

SAS Replace line break / carriage return with a space


I want to read a file and replace all the line break / carriage return with a space. Can you please help?

/*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;

Solution

  • I would suggest you just read the textfile line by line and then concat the lines together.

    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;
    

    otherwise you can replace linefeeds the same way i showed you in your last question:

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