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 2009, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 2 Dec 2009 10:05:23 -0500
Reply-To:     Michael Raithel <michaelraithel@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Michael Raithel <michaelraithel@WESTAT.COM>
Subject:      =?utf-8?B?UkU6IEVycm9yIEhhbmRsaW5nIMOi4oKs4oCcIERhdGEgU2V0cw==?=
In-Reply-To:  <200912011958.nB1Gtu2N004716@malibu.cc.uga.edu>
Content-Type: text/plain; charset="utf-8"

Dear SAS-L-ers,

Swamy posted the following:

> > I haven’t done any Error handling so far in SAS , > If I am looking for a specific data set in a folder , and If the data > set > does not exist , can I raise an exception ? > Also, being that the main or Base data set , I would not be able to > proceed without that data set, in a way I need to stop all the > processing > if the data set does not exist and come out of the processing , and > write > something like ‘Data Set not found’ in the output file. > > Can someone please help me. > Swamy, well, apparently several someone's can help you. And I am one of them!

Check out this snippet of code, ripped from the sun-bleached, desiccated, carcass of one of my old SAS programs:

**************************; * Allocate the Data file. *; ***************************; filename DATAFIL "&DATAFIL";

**************************************; * Determine if the Data file exists. *; **************************************; data _null_; notfound = fexist('DATAFIL'); call symput('notfound',notfound); if notfound = 0 then do; put '*** Attention: the file below was not found ***'; put '*** and could not be processed ***'; put "&DATAFIL"; put _all_; put '*** Attention: the file above was not found ***'; put '*** and could not be processed ***'; end; run;

%IF &NOTFOUND NE 0 %THEN %DO; *****************************************; * Process the records in the data file. *; *****************************************;

...more SAS code here...

In the example, you pass the full path (including filename) of the file you want to read into the program as Macro variable &DATAFILE. The DATA _NULL_ step checks for the file's existence. If it is not found, it writes an error message into your SAS log. You can use the &NOTFOUND Macro variable to either run or not run subsequent blocks of SAS code, depending upon whether or not your SAS program found the desired file.

What do you think? Could work, couldn't it?!?!?!

Swamy, best of luck in all of your SAS endeavors!

I hope that this suggestion proves helpful now, and in the future!

Of course, all of these opinions and insights are my own, and do not reflect those of my organization or my associates. All SAS code and/or methodologies specified in this posting are for illustrative purposes only and no warranty is stated or implied as to their accuracy or applicability. People deciding to use information in this posting do so at their own risk.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Michael A. Raithel "The man who wrote the book on performance" E-mail: MichaelRaithel@westat.com

Author: Tuning SAS Applications in the MVS Environment

Author: Tuning SAS Applications in the OS/390 and z/OS Environments, Second Edition http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=1&pc=58172

Author: The Complete Guide to SAS Indexes http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=1&pc=60409

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ We do not stop playing because we grow old. We grow old because we stop playing. - Anonymous +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


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