SAS Read multiple records from the same line without reference to the CRLF channel

I have only 1 line without feed (CRLF CRLF), the line of the line is a line of 4 characters, in this example it is "@A $ 3". Right now I don't need dlm and I need to import it from an external file (/files/Example.txt)

JOSH 30JUL1984 1011 SPANISH@A$3RACHEL 29OCT1986 1013 MATH@A$3JOHNATHAN 05JAN1985 1015 chemistry

I need this line in 3 lines:

JOSH 30JUL1984 1011 SPANISH
RACHEL 29OCT1986 1013 MATH
JOHNATHAN 05JAN1985 1015 chemistry

How can I do this in SAS?

* Added: your solutions work with this example, but I have a problem, a string that contains more than the maximum length allowed for the string (32,767 bytes),

For example, this line in the above exercise contains 5,000 entries.

Is it possible?

+4
source share
3 answers

DLMSTR= infile - "@A $3" . @@ , SAS, .

data test;
infile "/files/Example.txt" dsd dlmstr='@A$3';
informat var $255.;
input var $ @@;
run;

3 1 , , .

var.

+2

- :

( ):

DATA WORK.IMPORTED_DATA;
INFILE "/files/Example.txt" TRUNCOVER;
LENGTH Column1 $ 255;
INPUT @1 Column1  $255.;
RUN;

:

data result (keep=var1-var4);
set  WORK.IMPORTED_DATA;

delim = '@A$3';
end = 1;
begin = 1;
do while (end > 0);

    end = find(Column1, delim, begin);
    row = substr(Column1, begin, end - begin);

    var1 = scan(row, 1);
    var2 = scan(row, 2);
    var3 = scan(row, 3);
    var4 = scan(row, 4);

    begin = end + length(delim);
    output;
end;
run;
+1

, @A$3 :

data want (keep=subject);
    infile 'C:\sasdata\test.txt';
    input;                                                     
    length line $4500  subject $80;
    line=tranwrd(_infile_,"@A$3",'!');         

    do i=1 by 1 while (scan(line,i,'!') ^= ' ');
        subject=scan(line,i,'!');                       
        output;
    end;
run;

_infile_ , data. @A$2 . tranwrd() . scan().

Also, if you want to break up the values ​​into separate variables, just scan a few more. For example. put something like B = scan(subject,2);in a loop doand data want (keep= A B C D);. Greetings.

+1
source

All Articles