LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (May 2004, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 20 May 2004 10:20:17 +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
Comments:   To: "Choate, Paul@DDS" <pchoate@DDS.CA.GOV>
In-Reply-To:   <83F5497995A8D511965F00508BB929700271F75E@ddsexmb01.cahwnet.gov>
Content-Type:   text/plain; charset="us-ascii"

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.

-----Original Message----- From: Choate, Paul@DDS [mailto:pchoate@DDS.CA.GOV] Sent: 19 May 2004 17:35 To: 'ben.powell@cla.co.uk'; SAS-L@LISTSERV.UGA.EDU Subject: RE: Import CSV file, variable field numbers

Good morning Ben (or evening over there) -

Using your original model I'd read it like this (tested but not necessarily optimal):

<sascode> data pars; infile cards dsd missover; input (feild1-feild3) (: $50.) ; if feild1='' then delete;

cards; ISBN : 0002112787,, <snip> </snip> Farming and wildlife,"Mellanby , Kenneth",Collins ; 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; </sascode>

Sorry I didn't understand "speech marks" I thought you were referring to some mysterious embedded hex character, not double-quotes. The DSD option is use to handle CSV with quoted text. I revised the second datastep somewhat also.

Btw - I used to have a 1965 MGB - I loved reaching into the boot for a spanner to use under my bonnet to fix my hooter! YWIA

Paul Choate DDS Data Extraction (916) 654-2160

-----Original Message----- From: Ben Powell [mailto:Ben.powell@cla.co.uk] Sent: Wednesday, May 19, 2004 2:49 AM To: 'Choate, Paul@DDS'; SAS-L@LISTSERV.UGA.EDU Subject: RE: Import CSV file, variable field numbers

Thanks Paul, that does indeed work. It must have been the one thing I didn't try! I didn't post any cards as Randy's were an accurate example, once additional data rows were added. Of course they did not include the speech marks however - which I neglected to mention also. How can I tell the array handling to expect speech marks and thus to ignore commas (delimiters) that fall between them?

<cards> ISBN : 0002112787,, wild flowers of Britain and Northern Europe,"Blamey , Marjorie",Wm. Collins wild flowers of Britain and Northern Europe,"Fitter , Alastair",Wm. Collins wild flowers of Britain and Northern Europe,"Fitter , Richard",Wm. Collins

ISBN : 0002120208,, field guide to the birds of Britain and Europe,"Peterson , Roger",Collins

ISBN : 0002120356,, field giude to the trees of Britain and Northern Europe,"Mitchell , Alan",Collins

ISBN : 0002131781,, New Naturalist The Pollination of Flowers,"Proctor , Michael",Collins New Naturalist The Pollination of Flowers,"Yeo , Peter",Collins

ISBN : 000219080X,, field guide to caterpillars of butterflies and moths in Britain and Europe,"Carter , David",Collins field guide to caterpillars of butterflies and moths in Britain and Europe,"Hargreaves , Brian",Collins

ISBN : 000219239X,, Farming and wildlife,"Mellanby , Kenneth",Collins </cards> TIA


Back to: Top of message | Previous page | Main SAS-L page