Date: Sun, 1 Sep 1996 10:56:02 -0700
Reply-To: Don Cram <doncram@LELAND.STANFORD.EDU>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Don Cram <doncram@LELAND.STANFORD.EDU>
Organization: Graduate School Of Business, Stanford University
Subject: Re: Input problem; PERL line needed
In article <50b594$kmd@gsb-birr.Stanford.EDU>,
Michael C. Herron <pherron@gsb-birr.Stanford.EDU> wrote:
>In article <508ift$8vb@GSB-Kwanza.Stanford.EDU>,
>Don Cram <doncram@leland.Stanford.EDU> wrote:
>>I suggest you first replace the tabs by spaces in your input file.
>>Then reading it into SAS should be straightforward. Since you are
>>working in unix, that should be easy with a short PERL script. The
>>following would replace each tab with one space:
>>
>> perl -pe 's/\t/ /g' infile > outfile
>>
>>However, you want to replace each tab with as many spaces as are
>>needed. I am hoping someone else can suggest the PERL script which
>>would do that. I would use it too.
>
>What do you mean by "as many spaces as are needed?" If you want to
>replace a tab with 5 spaces, just do
>
>perl -pe 's/\t/ /g' infile > outfile
>
>Michael
>
The original questioner has a text file that has tabs. He said some
nonsense about "column-delimited" but really he meant that it _looks_
like it could be read into SAS using a fixed format read statement.
I.e. the data appears lined up nicely in columns. But sometimes the
several character-wide spaces are really tabs; some are literally
several space characters (I mean blanks, not Dr. Who).
How can one replace tabs with as many spaces so as not to change the
appearance on the screen?
Sample:
1111 2222 3333 444444444 5555
1111 2222 3333 5555
1111 2222 5555
1111 2222 5555
2222 5555
3333 5555
don
>>But as a total kludge, I think if you bring your file into a stupid
>>editor like "pico" and then save it, it will have done the replacement
>>of tabs for you.
>>
>>hope this helps
>>Don Cram
>>
>>
>>In article <199608281919.MAA05161@dfw-ix4.ix.netcom.com>,
>>Ronald Max Atwood Jr <matwood@IX.NETCOM.COM> wrote:
>>>Hi Y'all:
>>>
>>>I have run into an interesting input problem and thought I would check
>>>to see if any one out here is SAS-l land has run into this before.
>>>
>>>I have a "text" file that is supposed to be column delimited. I am not
>>>sure of the actual source of the file. I believe it was produced by an
>>>SQL query in ORACLE but I could not swear to that.
>>>
>>>As with all nice data sets there are supposed to be a fixed number of
>>>fields on any given line. However, in this case one field does not
>>>always have a value. On those lines were there is no value, there
>>>appears to be some sort of tab causing the pointer (in my text editor)
>>>to jump to the beginning of the next field. However, this "tab" effect
>>>does not carry over in SAS in the input statement. When I try to read
>>>specific data from specific colunms (using the @ symbol) I get
>>>erroneous results on those lines with the tab like effect. Something
>>>like the following:
>>>
>>>Text file (as it appears in my text editor):
>>>
>>>1111 2222 3333 4444 5555
>>>1111 2222 3333 5555
>>>
>>>Data dns;
>>>..
>>>input @1 field1 $4.
>>> @6 field2 $4.
>>> @11 field3 $4.
>>> @16 field4 $4.
>>> @21 field5 $4.;
>>>..
>>>run;
>>>
>>>In the case of line 1, the input is working fine. In the case of line
>>>2, positions 16-19 are not occupied by blanks (i.e. simply missing
>>>data) there is some sort of tab effect so that position 16 is infact
>>>the beginning of field5.
>>>
>>>The results of the data step seem to vary depending of the varyous
>>>approachs I take at the input process. The straight forward approach
>>>implied above gives the anticipated results for line 1. On line 2 I
>>>get field5 data in field4 and missing data in field5.
>>>
>>>The above example is a simplification of the real data set and input
>>>process. My questions to the SAS-L are: what kind of "text" file have
>>>I run into? What is it I am seeing in field4? Does anyone out there
>>>have any ideas how to read this file correctly?
>>>
>>>I am working in SAS611 on a Sun1000 workstation under SunOS2.3.
>>>
>>>Thanks in advance for any assistance.
>>>
>>>Max Atwood (matwood@ix.netcom.com)
>>
>>--
>>doncram@gsb-ecu.stanford.edu
>>http://www-leland.stanford.edu/~doncram
>
>
--
doncram@gsb-ecu.stanford.edu
http://www-leland.stanford.edu/~doncram
|