Re: Infile question: read the last observation #5

  • Follow


UNIX has a "tail" command, terribly handy at a time like this, to pull the
last X lines of a sequential file.  I imagine Windows "tail" functionality
is available via CYGWIN ( http://www.cygwin.com/ ), but for those not
wanting to go to those lengths, it appears as though "tail" functionality is
available for Windows XP / 2003 as well.
http://malektips.com/xp_dos_0001.html

That being the case, the last line may be read by using the FILENAME blah
PIPE stuff ( untested ):

filename last_line pipe "tail -1 'c:\your_dir\your_file'";

data new;
  infile last_line ;
  input clus days freq days1 days2 days3;
run;



-----Original Message-----
From: Charles Patridge [mailto:charles_s_patridge@PRODIGY.NET]
Sent: Monday, August 23, 2004 3:36 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Infile question: read the last observation


Paul,

Using a test file - here is what I got for results:

options fullstimer;
%let myfile = c:\download\sastest.txt;

data last_record ;
   length ml $3. order $6. dataname $8. datalabel $50.;
   array x(*) x1-x61;
   infile "&myfile" delimiter="!" dsd end = eof missover lrecl=1024
firstobs=4;
   input ml order dataname datalabel x1-x61;
   if eof ;
run ;

 The infile "c:\download\sastest.txt" is:
 File Name=c:\download\sastest.txt,
 RECFM=V,LRECL=1024

 109716 records were read from the infile "c:\download\sastest.txt".
 The minimum record length was 1024.
 The maximum record length was 1024.
 One or more lines were truncated.
 The data set WORK.LAST_RECORD has 1 observations and 65 variables.
 DATA statement used:
 real time           10.35 seconds
 user cpu time       9.70 seconds
 system cpu time     0.06 seconds
 Memory                            131k



***you use this: ;

data last_record ;
   length ml $3. order $6. dataname $8. datalabel $50.;
   array x(*) x1-x61;
   infile "&myfile" delimiter="!" dsd end = eof missover lrecl=1024
firstobs=4;
   input @;
   if eof;
   input ml order dataname datalabel x1-x61;
run ;

 The infile "c:\download\sastest.txt" is:
 File Name=c:\download\sastest.txt,
 RECFM=V,LRECL=1024

 109716 records were read from the infile "c:\download\sastest.txt".
 The minimum record length was 1024.
 The maximum record length was 1024.
 One or more lines were truncated.
 The data set WORK.LAST_RECORD has 1 observations and 65 variables.
 DATA statement used:
 real time           7.93 seconds
 user cpu time       6.79 seconds
 system cpu time     0.14 seconds
 Memory                            131k



HTH,
Charles Patridge
http://www.sconsig.com

Would be nice if there was a faster way to get last record of an external
file without knowing the # of records in an external file.

------------------------------------------------------------
This e-mail may be privileged and/or confidential, and the sender does not waive any related rights and obligations. Any distribution, use or copying of this e-mail or the information it contains by other than an intended recipient is unauthorized. If you received this e-mail in error, please advise me (by return e-mail or otherwise) immediately.

Ce courrier �lectronique est confidentiel et prot�g�. L'exp�diteur ne renonce pas aux droits et obligations qui s'y rapportent. Toute diffusion, utilisation ou copie de ce message ou des renseignements qu'il contient par une personne autre que le (les) destinataire(s) d�sign�(s) est interdite. Si vous recevez ce courrier �lectronique par erreur, veuillez m'en aviser imm�diatement, par retour de courrier �lectronique ou par un autre moyen.

============================================================
0
Reply harry.droogendyk1 (872) 8/23/2004 7:51:32 PM


0 Replies
50 Views

(page loaded in 1.261 seconds)

Similiar Articles:













7/18/2012 4:16:15 PM


Reply: