Date: Wed, 5 Jan 2011 05:46:09 -0500
Reply-To: Chris Brooks <Chris.Brooks@ONS.GOV.UK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Chris Brooks <Chris.Brooks@ONS.GOV.UK>
Subject: Re: Multiple Semicolons (was PROC EXPLODE and semicolons)
If you don't have control over the input file format and want to read in
lines which only contain 4 semicolons you could use the fopen, fread, fget
functions to read the input file into the file data buffer and then load
it into the data set eg for a file like this called semicolons.txt
aaaa
bbbb
cccc
;;;;
dddd
the following code would create five obs including one with four semicolons
filename infile 'd:\sas\semicolons.txt';
data fred(keep=avar);
length avar $4;
dsid=fopen('infile');
do while (fread(dsid)=0);
rc=fget(dsid,avar,4);
output;
end;
rc=fclose(dsid);
run;
If you had more variables you would of course have to parse the line but
that should be fairly straighforward.
Chris Brooks
SAS Technical Lead
Office for National Statistics
United Kingdom
On Tue, 4 Jan 2011 17:03:47 +0000, Keintz, H. Mark
<mkeintz@WHARTON.UPENN.EDU> wrote:
>Yes, I realized the deficiency of my response, but only after sending it.
>
>But chopping off the first character wouldn't actually be explicitly
required. One could assign the desired length to the variable, but use a
$ informat of length plus 1. The var would be automatically left
justified by the $ informat, but the stored variable would not
have "extraneous" blanks.
>
>data test;
> length A $4;
> input a $5.;
>datalines4;
>aaaa
> bbbb
> ;;;;
>;;;;
>
>It's still cheating but not as much.
>
>
>
>> -----Original Message-----
>> From: Jack Hamilton [mailto:jfh@stanfordalumni.org]
>> Sent: Tuesday, January 04, 2011 11:42 AM
>> To: Keintz, H. Mark
>> Cc: Jack Hamilton; SAS-L@LISTSERV.UGA.EDU
>> Subject: Re: Multiple Semicolons (was PROC EXPLODE and semicolons)
>>
>> Then it's not only semicolons.
>>
>> You could start every line with a leading blank, and then chop off the
>> first character before using the data, but that seems like cheating
>> somehow.
>>
>>
>>
>> On Jan 4, 2011, at 8:29 AM, Keintz, H. Mark wrote:
>>
>> > Put a leading blank in front of it.
>> >
>> >> -----Original Message-----
>> >> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
>> >> Jack Hamilton
>> >> Sent: Tuesday, January 04, 2011 11:22 AM
>> >> To: SAS-L@LISTSERV.UGA.EDU
>> >> Subject: Re: Multiple Semicolons (was PROC EXPLODE and semicolons)
>> >>
>> >> OK, how do you enter a line consisting only of 4 semicolons?
>> >>
>> >>
>> >> On Jan 4, 2011, at 8:15 AM, Gerhard Hellriegel wrote:
>> >>
>> >>> seems to be no problem:
>> >>>
>> >>> data a;
>> >>> infile datalines truncover;
>> >>> input a : $100.;
>> >>> datalines4;
>> >>> abc;;;;;efg
>> >>> 1233;;;;456
>> >>> a;;;;b
>> >>> ;;;;
>> >>> run;
>> >>>
>> >>> only the line with ONLY the 4 semicolons is not interpreted as
>> data.
>> >>>
>> >>> Gerhard
>> >>>
>> >>>
>> >>>
>> >>>
>> >>>
>> >>> On Tue, 4 Jan 2011 11:01:43 -0500, Kirby, Ted <ted.kirby@LEWIN.COM>
>> >> wrote:
>> >>>
>> >>>> Jack raises an interesting question. How would one read data
>> >> containing
>> >>>> 4 adjacent semicolons?
>> >>>>
>> >>>> Ted Kirby,
>> >>>> Consultant,
>> >>>> The Lewin Group, Inc.
>> >>>> 3130 Fairview Park, Suite 800
>> >>>> Falls Church, VA 22042
>> >>>> Phone: (703)269-5507
>> >>>> Fax: (703)269-5501
>> >>>> e-mail: ted.kirby@lewin.com
>> >>>>
>> >>>> -----Original Message-----
>> >>>> From: Jack Hamilton [mailto:jfh@alumni.stanford.org]
>> >>>> Sent: Tuesday, January 04, 2011 10:56 AM
>> >>>> To: Kirby, Ted
>> >>>> Subject: Re: [SAS-L] FW: Re: PROC EXPLODE and semicolons
>> >>>>
>> >>>> If your data contain semicolons, you would need to use PARMCARDS4
>> or
>> >>>> DATALINES4, because a single semicolon would be interpreted as "no
>> >> more
>> >>>> data".
>> >>>>
>> >>>> I don't know how you would read data containing 4 adjacent
>> >> semicolons.
>> >>>>
>> >>>>
>> >>>> On Jan 4, 2011, at 7:48 AM, Kirby, Ted wrote:
>> >>>>
>> >>>>> Data_null is correct, I do not often read data from
>> CARDS/DATALINES
>> >>>> very
>> >>>>> often, but I do occasionally. However, I still have not used 4
>> >>>>> semicolons in my code and my data have always read correctly.
>> >> Under
>> >>>>> what circumstances would I need to use multiple semicolons?
>> >>>>>
>> >>>>> PS: I have turned off the "return receipt requested" option for
>> >> this
>> >>>>> message. I apologize to you all for including it in my last
>> posts.
>> >>>>>
>> >>>>> -----Original Message-----
>> >>>>> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf
>> >> Of
>> >>>>> Data _null_;
>> >>>>> Sent: Tuesday, January 04, 2011 7:15 AM
>> >>>>> To: SAS-L@LISTSERV.UGA.EDU
>> >>>>> Subject: Re: PROC EXPLODE and semicolons
>> >>>>>
>> >>>>> On Mon, Jan 3, 2011 at 4:58 PM, Kirby, Ted <ted.kirby@lewin.com>
>> >>>> wrote:
>> >>>>>> However, I did not know that there were situations where
>> multiple
>> >>>>>> semicolons are needed. In my nearly 20 years of SAS programming
>> >> (the
>> >>>>>> last 10-12 years being nearly daily usage) I have never used
>> >> multiple
>> >>>>>> semicolons.
>> >>>>>
>> >>>>> My guess is that you don't read data from (CARDS/DATALINES) or
>> >>>>> PARMCARDS very often I know I don't. My data is most often in a
>> >> SAS
>> >>>>> data set or and external file. So the opportunity to need the
>> "4"
>> >>>>> versions of these statements would be few indeed.
>> >>>>> ************* IMPORTANT - PLEASE READ ********************
>> >>>>>
>> >>>>> This e-mail, including attachments, may include confidential
>> and/or
>> >>>> proprietary information,
>> >>>>> and may be used only by the person or entity to which it is
>> >> addressed.
>> >>>> If the reader of this
>> >>>>> e-mail is not the intended recipient or his or her authorized
>> >> agent,
>> >>>> the reader is hereby
>> >>>>> notified that any dissemination, distribution or copying of this
>> >>>> e-mail is prohibited. If you
>> >>>>> have received this e-mail in error, please notify the sender by
>> >>>> replying to this message
>> >>>>> and delete this e-mail immediately.
>> >>>>>
>> >>>>
>> >>>> ************* IMPORTANT - PLEASE READ ********************
>> >>>>
>> >>>> This e-mail, including attachments, may include confidential
>> and/or
>> >>> proprietary information,
>> >>>> and may be used only by the person or entity to which it is
>> >> addressed.
>> >>> If the reader of this
>> >>>> e-mail is not the intended recipient or his or her authorized
>> agent,
>> >> the
>> >>> reader is hereby
>> >>>> notified that any dissemination, distribution or copying of this
>> e-
>> >> mail
>> >>> is prohibited. If you
>> >>>> have received this e-mail in error, please notify the sender by
>> >> replying
>> >>> to this message
>> >>>> and delete this e-mail immediately.
>> >>>>
|