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 (July 2003, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 3 Jul 2003 09:58:49 +0100
Reply-To:   Peter Crawford <Peter@CRAWFORDSOFTWARE.DEMON.CO.UK>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Peter Crawford <Peter@CRAWFORDSOFTWARE.DEMON.CO.UK>
Subject:   Re: fopen() and infile correspondence
Comments:   To: "Gleb V. Kotelnitsky" <kiz@pth.ntu-kpi.kiev.ua>
In-Reply-To:   <bdv3o5$1trj$1@news.ntu-kpi.kiev.ua>

Hi Gleb When reading excel topics, I think you'll only get one record whether in a data step of through fread() Your original posting extracted topics in a datastep using tab delimiters and @@ to keep the buffer through all datastep iterations ( and buffers ), until the buffer(s) is exhausted. The fsep() function is used to define delimiters in that fxxxx() function context, and defining the tab separator inside %sysfunc() is a bit problematic - I don't know how, but that doesn't mean it can't be done - ;-))

I think a general solution should assume the topics file might generate more than one buffer. Then you need two loops, First, while fread() delivers something, and second while fget() parses the buffer. You may find it worth modelling the fxxxx() functions and loops, in a datastep first, to reduce the problems introduced by the %sysfunc macro environment. Good Luck Peter Crawford

Gleb V. Kotelnitsky <kiz@pth.ntu-kpi.kiev.ua> writes >Peter Crawford <PeterDOTCrawfordATblueyonder.co.uk@.> wrote: >PC> In Ace's solution, you (may) need to use fclose() rather than close() >PC> I think the fread() should be outside the loop. But that depends on >PC> the record-read buffering. >thank you, placing fread outside the loop really helps, but i wonder >why? >PC> Persuading fget() to respect the tab-delimiters seems... >PC> a bit more complex! > > >i really supplied just a raw piece of code >the real one is as follows >%macro tr; >%let tref= ; >%let %rc=%sysfunc(filename(tref,excel|system!topics,dde)); >%let topics=%sysfunc(fopen(&tref,s,,v)); >%put &topics &tref; >%do %while (not %sysfunc(fread(&topics))); > %let %rc=%sysfunc(fget(&topics,var)); > %put %&var; >%end; >%let %rc=%sysfunc(fclose(&topics)); >%let %rc=%sysfunc(filename(&topics)); >%mend > >PC> "Ace" <b.rogers@virgin.net> wrote in message >>> >>> I'm assuming you've only given part of your code, particularly as you >>> don't seem to be using sysfunc in an assignment, so the result (the >>> return code) would then be interpreted as a SAS statement and give an >>> error. >>> >>> I've put some wrapping round your code and it works just fine. Maybe >>> you're just missing part of it. Here's my code: >>> >>> filename fred '.kshrc' ; >>> %macro fred ; >>> %let topics=%sysfunc(fopen(&tref,s,,v)); >>> %do i = 1 %to 10 ; >>> %let rc = %sysfunc(fread(&topics)); >>> %let rc = %sysfunc(fget(&topics,var)); >>> %put &var ; >>> %end; >>> %let rc = %sysfunc(close(&topics)) ; >>> %mend ; >>> >>> %let tref = fred ; >>> %fred ;

-- Peter Crawford

available for SAS consultancy contracts


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