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 (December 2003, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 12 Dec 2003 13:55:45 -0800
Reply-To:   cassell.david@EPAMAIL.EPA.GOV
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "David L. Cassell" <cassell.david@EPAMAIL.EPA.GOV>
Subject:   Re: Check in a SAS session if ascii file exist
Content-type:   text/plain; charset=US-ASCII

lpogoda <lpogodajr292185@COMCAST.NET> replied: > Depending on what created them, human readable files can and do have a > variety of extensions. Conversely, just about any file can be renamed to > anything else without changing it's content. For instance, I've just > finished on a project where 100's of ASCII (in the above sense of human > readable) files were received with an extension of .aws. And due to an > update of some media player or other, my office pc thinks that version 6 SAS > datasets are Macintosh sound files at the moment. In other words, the file > name or extension is not an infallible guide to the file contents. Not by > half. > > So, I read the above as is there any test that will tell you if a > file-that-a-human-can-read-as-if-reading-a-page-of-a-book exists?

Perl has an approximation. In Perl there are a host of operators that look like -X (where 'X' is a single alphabetic character).

-e $file # $file exists -f $file # $file is a 'plain' file -T $file # $file is an ASCII text file

The -T operator reads the first block of the file and counts up the number of control characters and characters with the high bit set. If that total is over 30% of the first block (or if there is a null in the first block) then the file is regarded as other than an ASCII text file, and (-T $file) returns 0 (for false). This could obviously be copied in SAS using recfm=N to scan through the first umpteen bytes and make the same evaluation.

Since you have to read the file to do the -T test, usually you want to check that the file exists first, and abend if it isn't there:

if -e $file && -T $file {other code ...};

HTH, David -- David Cassell, CSC Cassell.David@epa.gov Senior computing specialist mathematical statistician


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