Reputation: 23
First of all, I beg your pardon for the lack of my technical english. I'll try to make my self clear with some images.
I'm trying to import a text file "as is" to SAS. It looks like this:
In text:
YPJC200,FG;00899;Pesos;0;3500;EDENOR S.A. "B" 1 VOTO
TRAD15.9FF;00902;Pesos;0;3000;EDENOR S.A. "B" 1 VOTO
It's a text file delimited with semicolon ";" but in addition it has:
Of course I'm getting errors or column displacements.
As I said before, I want to import the full file "as is" in one column, replace the three first lines (that are wrong headers), replace with correct ones in one line, and export to text file again. So I need to get the same file with headers changed.
I'm using this code after trying other things:
DATA WORK.WANT;
INFILE '\\server\Interfaces\position.txt'
DSD LRECL = 32767 MISSOVER DLM = '|';
INFORMAT CAMPO $1500.;
INPUT CAMPO $;
IF _N_ >= 6;
RUN;
With "INFORMAT CAMPO $1500.;" I'm loading the file in just one column.
I'm using " DLM = '|' " to avoid delimiters. I can't set any delimiter other than this because my file has all of them (; . , ) except of course the pipe. If avoid the "DLM" option it assumes comma delimiter, so it's unuseful to.
But now I have the problem with double quotes.
I'm getting double quotes everywhere like this:
"YPJC200,FG;00899;Pesos;0;3500;EDENOR S.A. ""B"" 1 VOTO"
"TRAD15.9FF;00902;Pesos;0;3000;EDENOR S.A. ""B"" 1 VOTO"
So, the direct question is: How can I import the file exactly as it is, line by line, char by char, in the simplest way?
Thanks in advance
Upvotes: 0
Views: 2522
Reputation: 9569
Don't use DSD
in your infile statement. This will make SAS treat quote characters differently from other characters, which you don't want to do here.
Also, you can write your file straight out to another text file with fixed headers without ever creating a SAS dataset from it, e.g.
DATA _null_;
INFILE '\\server\Interfaces\position.txt' LRECL = 32767 firstobs = 6;
file "\\path\to\fixed\file.txt" ;
INPUT;
if _n_ = 1 then put "var1,var2,..."; /*insert fixed header row text here*/
put _infile_;
RUN;
Upvotes: 0
Reputation: 51611
If you want to read the full line into one long character variable why are you mentioning anything to do with delimiters on the INFILE statement? If you want to preserve leading spaces then use the $CHAR
informat.
data want ;
infile '\\server\interfaces\position.txt' truncover firstobs=6;
input campo $char1500.;
run;
Upvotes: 0