| Date: | Thu, 20 May 2004 17:29:19 +0100 |
| Reply-To: | ben.powell@cla.co.uk |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Ben Powell <Ben.powell@CLA.CO.UK> |
| Organization: | cla |
| Subject: | Re: Import CSV file, variable field numbers |
|
| In-Reply-To: | <83F5497995A8D511965F00508BB929700271F76E@ddsexmb01.cahwnet.gov> |
| Content-Type: | text/plain; charset="us-ascii" |
Thanks Paul. Don't know why I couldn't get the infile to work...
I've found this whole exercise spectacularly exciting as arrays are the one
area in vanilla SAS I can't seem to fathom, partly because I rarely need one
so have few examples to work through. Getting there...
Evening spent int coal mine with missus in front o' box eatin ma fish n
chips will be soo much better now 'appen it will!
Ben.
-----Original Message-----
From: Choate, Paul@DDS [mailto:pchoate@DDS.CA.GOV]
Sent: 20 May 2004 17:02
To: 'ben.powell@cla.co.uk'; SAS-L@LISTSERV.UGA.EDU
Subject: RE: Import CSV file, variable field numbers
Can't resist myself really - mine was a bit of an old banger, but it was
better than a slap in the face with a wet kipper. I'd just love to tonk it
up the motorway. ;-)
If you replace the cards reference on your infile statement with your
fileref and also delete the cards statement and inline data, then the
program should work exactly the same, except for pointing at the file rather
than the inline cards. The extra array in the second datastep should not
matter, it's just a different way of handling the data.
I placed your data into data.txt (you'll need a path or put it in your
default directory) and it ran just like you want:
data pars;
infile 'data.txt' dsd missover;
input (feild1-feild3) (: $50.) ;
if feild1='' then delete;
run;
data pars(drop=feild1-feild3 i j);
retain isbn det1-det30 j;
set pars end=eod;
length isbn $ 10 det1-det30 $ 50;
array det(30) det1-det30;
array fld(3) feild1-feild3;
if feild1=:'ISBN' then do;
if _n_>1 then output;
isbn=scan(feild1,3,' ');
do j=1 to 30; det(j)=' '; end;
j=0;
end;
else do;
do i=1 to 3; det(i+j)=fld(i); end;
j+3;
end;
if eod then output;
run;
good luck Ben.
Paul Choate
DDS Data Extraction
(916) 654-2160
-----Original Message-----
From: Ben Powell [mailto:Ben.powell@cla.co.uk]
Sent: Thursday, May 20, 2004 2:20 AM
To: 'Choate, Paul@DDS'; SAS-L@LISTSERV.UGA.EDU
Subject: RE: Import CSV file, variable field numbers
Yeah ok enough of the English jokes already, go eat some to-mate-os :-)
Nice car by the way. Shame they never did a V10 8 litre (something in cubic
inches) SUV variant!
...
Is the only way to get this to work to use cards? There are 14,000 lines in
the csv.
Using dsd with a conventional infile scuppers the latter part of the program
as the array can no longer be used to parse the additional fields.
Thanks also for adding another array into the bargain and confusing me even
more!
Ben.
|