|
Scott,
Your wish is granted in version 9, and Richard has provided you with one
answer if you are stuck with version 8 so you should be one happy junior
tomcat. One question I have for you, however, in the interest of your self
education and others at your level on SAS-L, is, did you consider what SAS
might do with the multiple ======'s when used in the DLM infile option in
version 8? Surely, you did not think SAS would just ignore them? For the
sake of all those at your level on SAS-L, please tell us what you thought
would happen to the extra "===='s".
Joe Whitehurst
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Scott
Bass
Sent: Sunday, May 22, 2005 8:37 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: I wish SAS would allow a *string* as a field delimiter
Hi,
(for brevity, this post is a simplified example of a more complex
problem...)
Summary: Is there a way to make SAS accept a *string* of characters as a
field delimiter when reading a flat file? From the docs, it looks like NO
(rats!) but thought I'd ask.
Details: I have to read in a file with embedded carriage returns in the
fields. I note Richard DeVenezia's post on how to do this:
http://listserv.uga.edu/cgi-bin/wa?A2=ind0206D&L=sas-l&P=R33076.
Say this is the sample file:
This is record 1, VAR1
With one embedded carriage return
=====
This is record 1, VAR2
With two embedded carriage returns
Oops, and a =line= containing a single = character
=====
This is record 1, VAR3
With three embedded carriage returns
=====
This is record 2, VAR1
With one embedded carriage return
=====
=====
This is record 2, VAR3
With three embedded carriage returns
=====
What I want is two observations, three vars, embedded CRs in the vars. For
obs 2, var2 is missing.
I *wish* I could say:
data foo;
infile 'c:\temp\arbitrary.txt' recfm=n dsd dlm='====='; /* or perhaps
"\n=====\n" in hex */
length var1-var3 $5000;
input var1-var3;
... any additional processing ... ;
run;
but dlm only accepts a single character for the delimiter. Bummer.
Rationale: I'd like the input file to be "human readable". If I change the
delimiter to Tab, #, etc, the file is hard to "human" read. If I could
specify the exact *string* I want to delimit fields, it would be easier to
accomplish this.
(The actual "file" is a PIPE to a Perl script. Another (ugly) option is a
command line switch to have two output types: one for SAS import, and the
other for STDOUT)
Any bright ideas, O gurus of SAS-L?
Regards,
Scott
P.S.: SAS v8.2, Windows
|