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 (November 2007, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 27 Nov 2007 14:48:22 -0500
Reply-To:     Jack Clark <JClark@CHPDM.UMBC.EDU>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jack Clark <JClark@CHPDM.UMBC.EDU>
Subject:      Re: Limit Bytes Being Read from Text File on Infile Statement?
Comments: To: "Terjeson, Mark" <Mterjeson@russell.com>
In-Reply-To:  <16FD64291482A34F995D2AF14A5C932C015A7AA2@MAIL002.prod.ds.russell.com>
Content-Type: text/plain; charset="us-ascii"

Mark,

Thanks for the reply.

My text file is fixed length (7984 bytes), and I need to read in 2 fields.

data reas8; infile myfile missover lrecl=7984; input @475 subreasn $2. @477 ICN3 $17. ; run;

Maybe I am thinking of another language I used to use long ago? But I thought I had used something in SAS in the past to say "don't read all the way out to 7,984 bytes because you only need to look in the first 500 bytes for what I need". It would have been on either MVS or VSE mainframe - SAS Version 6.

Jack Clark Research Analyst Center for Health Program Development and Management University of Maryland, Baltimore County

-----Original Message----- From: Terjeson, Mark [mailto:Mterjeson@russell.com] Sent: Tuesday, November 27, 2007 2:38 PM To: Jack Clark; SAS-L@LISTSERV.UGA.EDU Subject: RE: Limit Bytes Being Read from Text File on Infile Statement?

Hi Jack,

If the lines of text are a fixed length then the LRECL= works good, if the lines are not fixed length then the $VARYING is handy.

If you want to fetch just the first 500 bytes of each line then the trick is to get the record pointer to jump to the next starting point. The easiest way to do this is to just go ahead and set your LRECL to the physical line length and then just use the INPUT @1 mychunk $500. to load only the first 500 bytes, then the next starting point will automatically be in the right place.

If you meant that the text lines are 8000 (and not the file size) then set your LRECL to 8000 in order for the record pointer to hop to each physical record and then just use the INPUT statement options to read just the pieces you want.

If varying line lengths just INPUT the line with the $VARYING options and use SUBSTR() to chop out the first 500 bytes, etc. e.g. filename yourfile 'c:\mycode.sas'; data theds(keep=theline); length theline $200; infile yourfile length=lenvar; input @1 theline $varying. lenvar; mychunk = substr(theline,1,500); run;

Hope this is helpful.

Mark Terjeson Senior Programmer Analyst, IM&R Russell Investments

Russell Investments Global Leaders in Multi-Manager Investing

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Jack Clark Sent: Tuesday, November 27, 2007 11:24 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Limit Bytes Being Read from Text File on Infile Statement?

Hello everyone,

Am I imagining things or isn't there some option/parameter on the INFILE or INPUT statement that limits how many bytes of an external file is read?

For example, if I have a text file that is 8,000 bytes long, and the only variables I want to read in are in the first 500 bytes, isn't there a way to tell SAS to only read the first 500 bytes?

It's been a while, but I thought I remembered something like that? Or maybe you just set the LRECL= the lower value with the MISS/FLOW/TRUNCOVER option??

Thanks for any suggestions.

Jack Clark

Research Analyst

Center for Health Program Development and Management

University of Maryland, Baltimore County


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