Here's an example of how you can process the data as you read it.
filename CSV "~/aa.txt";
data _null_;
file CSV;
put '"aa";"bb' '0d0a'x 'bb";"cc"' '0d0a'x '"xx";"yy";"zz"';
put '"11";"22";"33"';
run;
data WANT;
infile CSV recfm=n eof=EOF;%* Read the file in stream mode;
length A B C TMP $8 ; %* Declare variables;
retain A B TMP; %* Retain variables
input X $1. @@; %* Save one character of data;
if X='"' then do; %* Look for quote in data;
Q+1; %* Count quotes;
if Q=2 then do; %* Second quote: End of string;
VARNO+1; %* Count variables ;
if VARNO=1 then A=TMP; %* Save value into variable;
if VARNO=2 then B=TMP; %* Save value into variable;
if VARNO=3 then do; %* Last variable: Save record;
C=TMP; %* Save value into variable;
output; %* Save record;
VARNO=-1; %* Reset variable counter;
end;
else do; %* Not last variable: skip to next data character;
do until (X not in (';','"','0d'x,'0a'x));
input X $1. @@;
end;
TMP=X; %* Save first character of data;
end;
Q=1; %* Second quote processed, reset quote counter;
end;
end;
else
TMP=catt(TMP,X); %* Character is not a quote: Append it into value;
return; %* Go to top to read next character;
eof: %* EOF found;
stop; %* Stop the data step;
keep A B C;
run;
proc print noobs;
run;
A
B
C
aa
bb bb
cc
xx
yy
zz
11
22
33
... View more