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 (August 2001, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 31 Aug 2001 14:47:15 -0600
Reply-To:     Jack Hamilton <JackHamilton@FIRSTHEALTH.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jack Hamilton <JackHamilton@FIRSTHEALTH.COM>
Subject:      Re: FW: Testing for empty file.
Comments: To: mdurbin@erac.com
Content-Type: text/plain; charset=us-ascii

If you're lucky. Or nobs might be missing or wrong or some large but possibly plausible number if you're unlucky.

See <http://www2.sas.com/proceedings/sugi26/p095-26.pdf> for an examples.

-- JackHamilton@FirstHealth.com Development Manager, Technical Group METRICS Department, First Health West Sacramento, California USA

>>> "Mike Durbin" <mdurbin@ERAC.COM> 08/31/2001 1:26 PM >>> Here is the way I test for the number of observations in a file:

311 data _null_; 312 dsn = open('work.all'); 313 nobs = attrn(dsn,'nobs'); 314 rc = close(dsn); 315 put 'nobs = ' nobs; 316 run;

nobs = 2055 NOTE: DATA statement used: real time 0.00 seconds

The nobs variable will equal the number of observations in the file or -1 if there are none.

Mike Durbin

-----Original Message----- From: Jack Hamilton [mailto:JackHamilton@FIRSTHEALTH.COM] Sent: Friday, August 31, 2001 2:42 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Testing for empty file.

SAS will never set _N_ to blank; it will always be an integer >= 1.

If there are no records in the file, execution will stop at the first INPUT statement, so the code below that will never execute.

You want to check whether the END= variable is true *before* you execute the INPUT statement.

By the way, I recommend against calling your END= variable "EOF" There's also an EOF= option. SAS won't get confused, but you might. Using the EOF= option is another way to handle your problem.

-- JackHamilton@FirstHealth.com Development Manager, Technical Group METRICS Department, First Health West Sacramento, California USA

>>> "Valone, Toren W." <TValone@DMV.CA.GOV> 08/31/2001 11:55 AM >>> How do I test for an empty file?? Here is my code below, It seems that if the file is empty, then Sas does not populate the _n_ variable. I have also tried a put all with no results.

//STEP030 EXEC SAS,OPTIONS='NONEWS' //SASLOG DD SYSOUT=* //SASLIST DD SYSOUT=* //***************************************************************// //* WRITES OUT ESP SYMBOLICS FOR RECEIVE JOB *// //***************************************************************// //ESPIN DD DSN=&&ESP,DISP=(,PASS) //ESPOUT DD DSN=MV.PDG.EDI.ESP,DISP=OLD //SYSIN DD * OPTIONS NOCENTER DQUOTE ; DATA STEP1; INFILE ESPIN END = EOF; INPUT ; IF _N_ = '' THEN DO; PUT '_N_ IS BLANK'; END; IF _N_ = 1 THEN DO; PUT '_N_ IS =1 '; END;


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