Date: Tue, 20 Jun 2006 17:18:42 -0400
Reply-To: Venky Chakravarthy <swovcc@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Venky Chakravarthy <swovcc@HOTMAIL.COM>
Subject: Re: infile data with semicolon delimiter
On Tue, 20 Jun 2006 20:16:45 +0300, mom <momnothere@GMAIL.COM> wrote:
>how might I read in a file that looks like this (sas pseudocode included)
>
>data a; informat type $; infile cards DLM=";";
>cards;
>ford taurus ; mustang GTO; whatever v whatever; data wraps around like
>this; some more data; short data; very long data line here;
>;;;
>
>run;
>
>expected result
>list of type
>
>ford taurus
>mustang GTO
>whatever v whatever
>data wraps around like this
>some more data
>short data
>very long data line here
I cannot think of a better solution to this than the following. The trick
is to parse the _infile_ buffer before writing anything out. This is a
clumsy problem.
data a (keep=type);
length type lasttype $50 ;
retain lastsemi lasttot lasttype ;
infile cards4 ;
input ;
cntsemi = length(_infile_) - length(compress(_infile_,";")) ;
semiend = (substr(_infile_,length(_infile_),1) ^= ";") ;
totcnt = cntsemi - semiend ;
do i = 1 to cntsemi ;
if lastsemi^=lasttot
then type = left(trim(lasttype)||" "||scan(_INFILE_,i,';')) ;
else type = left(scan(_INFILE_,i,';')) ;
lastsemi = lasttot ;
output ;
end ;
lasttype = left(scan(_INFILE_,cntsemi+1,';')) ;
lastsemi = semiend ;
lasttot = totcnt ;
cards4;
ford taurus ; mustang GTO; whatever v whatever; data wraps around like
this; some more data; short data; very long data line here;
;;;;
run;
Venky Chakravarthy
|