Date: Fri, 7 Sep 2007 09:48:24 -0400
Reply-To: Jack Wozek <Jack.A.Wozek@BOS.FRB.ORG>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jack Wozek <Jack.A.Wozek@BOS.FRB.ORG>
Subject: Problem importing some pipe-delimited text files
Content-Type: text/plain; charset="US-ASCII"
I need to read in a sizable volume of pipe-delimited text files. Using
some code adapted from "Reading a Pipe-Delimited File with in a
Comma-Delimited File" (Carey Smoak), my plan is to read the file names
from the directory, put the file names into separate macrovariables, and
use proc import inside a do loop (copied below). I opted for the simple
proc import because the files are not standard (different combinations of
column, but all have a common denominator of columns I need). I want this
to be as automated and maintenance-free as possible since this will be a
repeated process completed by others. However, I am running into an error
with some files. One of the columns I am reading has a text description,
and in some cases it is very long. When a long description appears in the
first row of data (or the first 20 I gather), proc import guesses an
informat/format that is unknown to SAS (see error below). A past posting
(Howard Schreier, Dec 26, 2002) suggested block copying the data step code
generated in the log by proc import, fixing the error, and then re-running
the data step code. I tried this and it works. However, I would like
something more efficient since I am dealing with thousands of files.
Any ideas how to code around this problem? Or, any ideas ideas how to
uniformly identify when this error occurs to speed up the manual fix
/* Import Code
%do i = 1 %to &filecount;
PROC IMPORT OUT= data.&&fileb&i
Delimiter = "|";
getnames = yes;
130 informat SDR_DESCRIPTION_TEXT $12E3. ;
ERROR 228-185: Informat 12E3 is unknown.
ERROR 22-322: Syntax error, expecting one of the following: a name, -, ;,
_CHARACTER_, _CHAR_, _NUMERIC_.
ERROR 200-322: The symbol is not recognized and will be ignored.