06-22-2012 12:23 PM
When run a SAS using interactive mode, when error happened,how to stop the code and not override the rest dataset with an empty dataset?
if we select the follow three datasteps and submit them together, in the first step,dataset 'a' would be created ,
then in the second ,there will be a error bacuse no dataset named sashelp.class_notexist .
and then in the third step, dataset 'a' will be destroyed .
How to specify an option to protect dataset 'a' after error happen? so when an error happen SAS will stop do any other thing and keep dataset 'a' as the first step.
06-22-2012 01:11 PM
There are many solutions.
One is simply using different programming practice, where you don't reuse the names of datasets in a program. Then data a never gets overwritten because the last data step is named data b;
The other way that comes to mind is to check the number of observations in data one, and if you find out that data one has zero observations, you don't perform the next step. I'm pretty sure you would have to do this with macros.
06-22-2012 01:19 PM
The code is just an example; I want to find a mothod deal with error,and when error happend not go ahead to anything,
another example:After the following code is finshed I don't want sashelp.class be replaced.
data errorone;/*This dataset just for generate an error */
/*when error happened next step should not be run,----------how to do it?? */
06-22-2012 01:35 PM
Yes, I understand your code is an example. But now you have provided more code, which is also an example, and ignored my suggestions.
As I said, the simplest way is to not re-use dataset names in your code. Then sashelp.class doesn't get replaced. Is that not a valid solution for you?
As I said, you can check to see how many observations are in errorone, and if it is zero, do not perform the next step. Is that not a valid solution for you?
06-22-2012 04:32 PM
Thank you ,
but I think you must mis-understand my question.
1. I need the dataset to be override by another dataset if there was no error happen.
2.As you said ,you can check error and not perform next if error there,this sounds like the solution I need ,but what is it? I will be very appreciate if you would show me the detail.
06-23-2012 03:30 PM
To get the most control you would need to wrap your code into a macro. Then you can use macro logic at key points to stop processing. Using you simple example you could do something like:
%if not &syserr %then %do;
06-23-2012 10:18 PM
You can check for specific conditions (using macro language). But you cannot check for "any sort of error" until after the DATA step runs. Here are a few tools that may come in handy.
fileexist checks for the existence of a folder or raw data file
exist checks for the existence of a SAS data set
So you could (inside a macro) code:
%if %sysfunc(exist(mylib.my_dataset)) %then %do;
Then the %do group code would only run when your SAS data set exists.
Is that the sort of thing you are looking for?
06-24-2012 10:39 PM
You need a special dataset option.
REPEMPTY= Data Set Option
Specifies whether a new, empty data set can overwrite an existing SAS data set that has the same
06-25-2012 03:33 PM
Also ,For both the convenience of replacing existing data sets with new ones that contain data and the protection of not overwriting existing data sets with new empty ones that are created by accident, set REPLACE=YES and REPEMPTY=NO.
one thing need to be mentioned, system options will replace only permernent dataset,
temperory dataset need to use replace= dataset option
06-25-2012 04:06 PM
How about the following code ,please advise me,
data a(%if &monk=1 %then %do; replace=no %end; %else %do; replace=yes %end);