From: Joe Matise on
In addition to Ron's very useful advice, I would suggest looking at the
_ERROR_ automatic variable, and _IORC_ - they're most commonly used for
error trapping/raising.

-Joe

On Tue, Dec 1, 2009 at 1:58 PM, SAS Swamy <sasswamy(a)gmail.com> wrote:

> Hello,
>
> I haven=92t 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 =91Data Set not found=92 in the output file.
>
> Can someone please help me.
>
> Thanks
> - Swamy
>
From: Michael Raithel on
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(a)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
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
From: "Data _null_;" on
Your technique requires a macro, which may not be desirable. Another
similar approach would be to check and read in the same step. The
major difference is this approach creates a data set with 0 obs if the
input data file does not exist, I would consider that an advantage.

You could also create a macro variable to act as a flag (HASOBS).

filename DATAFILE 'ft15f001.dat';

data test;
length file $128;
File = pathname('DATAFILE');
if NOT fexist('DATAFILE') then do;
putlog 'WARNING: ' File= 'was not found, data set will be empty.';
_n_ = 0;
end;
else do;
putlog 'NOTE: ' File= ' exists and will be read now.';
infile dummy filevar=file end=eof length=l;
do while(not eof);
input line $varying100. l;
output;
end;
_n_ = 1;
end;
call symputX('HASOBS',_n_);
stop;
run;

%put NOTE: HASOBS=&hasobs;


On 12/2/09, Michael Raithel <michaelraithel(a)westat.com> wrote:
> 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(a)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
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
From: rjf2 on
Mikkeeee!
You missed an excellent opportunity to note the paper in which you published the code:

Paper 215-29
Measuring SAS® Software Usage
On Shared Servers
With the RTRACE Facility
Michael A. Raithel

http://www2.sas.com/proceedings/sugi29/215-29.pdf

see also:

http://www.sascommunity.org/wiki/Tips:Measure_SAS_Performance_with_the_LOGPARSE_SAS_Macro

Raithel: Measure_SAS_Performance_with_the_LOGPARSE_SAS_Macro
http://www2.sas.com/proceedings/sugi30/219-30.pdf

Fehd: Modifying the LogParse PassInfo Macro
http://www.nesug.org/proceedings/nesug06/as/as08.pdf

good .sig, worth repeating

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

Ron Fehd the wiki maven CDC Atlanta GA USA RJF2 at cdc dot gov
From: saslearn chicago on
Thanks a lot for everyone suggestion on this Topic, will try and let you
know for any question

- swamy
On Wed, Dec 2, 2009 at 10:31 AM, Data _null_; <iebupdte(a)gmail.com> wrote:

> Your technique requires a macro, which may not be desirable. Another
> similar approach would be to check and read in the same step. The
> major difference is this approach creates a data set with 0 obs if the
> input data file does not exist, I would consider that an advantage.
>
> You could also create a macro variable to act as a flag (HASOBS).
>
> filename DATAFILE 'ft15f001.dat';
>
> data test;
> length file $128;
> File =3D pathname('DATAFILE');
> if NOT fexist('DATAFILE') then do;
> putlog 'WARNING: ' File=3D 'was not found, data set will be empty.';
> _n_ =3D 0;
> end;
> else do;
> putlog 'NOTE: ' File=3D ' exists and will be read now.';
> infile dummy filevar=3Dfile end=3Deof length=3Dl;
> do while(not eof);
> input line $varying100. l;
> output;
> end;
> _n_ =3D 1;
> end;
> call symputX('HASOBS',_n_);
> stop;
> run;
>
> %put NOTE: HASOBS=3D&hasobs;
>
>
> On 12/2/09, Michael Raithel <michaelraithel(a)westat.com> wrote:
> > Dear SAS-L-ers,
> >
> > Swamy posted the following:
> >
> > >
> > > I haven=E2=80=99t 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 =E2=80=98Data Set not found=E2=80=99 in the output fil=
e.
> > >
> > > Can someone please help me.
> > >
> > Swamy, well, apparently several someone's can help you. And I am one o=
f
> them!
> >
> > Check out this snippet of code, ripped from the sun-bleached, desiccate=
d,
> carcass of one of my old SAS programs:
> >
> > **************************;
> > * Allocate the Data file. *;
> > ***************************;
> > filename DATAFIL "&DATAFIL";
> >
> > **************************************;
> > * Determine if the Data file exists. *;
> > **************************************;
> > data _null_;
> > notfound =3D fexist('DATAFIL');
> > call symput('notfound',notfound);
> > if notfound =3D 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 writ=
es
> 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, dependin=
g
> 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 onl=
y
> and no warranty is stated or implied as to their accuracy or applicabilit=
y.
> People deciding to use information in this posting do so at their own ris=
k.
> >
> > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > Michael A. Raithel
> > "The man who wrote the book on performance"
> > E-mail: MichaelRaithel(a)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=3D1&pc=3D58172
> >
> > Author: The Complete Guide to SAS Indexes
> > http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=3D1&pc=3D60409
> >
> > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > We do not stop playing because we grow old.
> > We grow old because we stop playing. - Anonymous
> > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >
>