☑ This topic is solved.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 12-15-2024 04:22 AM
(2765 views)
Hello
Is it possible to tell SAS to give error when "uninitialized".
For example:
I want to get error here and I even dont see warning
Data have;
X=10;
run;
data want;
y=z*5;
Run;
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can use the VARINITCHK system option, and set it to ERROR (or WARN if you only want a warning):
1 options varinitchk=error; 2 3 data want; 4 y=z*5; 5 Run; ERROR: Variable z is uninitialized. NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.WANT may be incomplete. When this step was stopped there were 0 observations and 2 variables. WARNING: Data set WORK.WANT was not replaced because this step was stopped.
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What is the problem here? You can search the log for "uninitialized", just like you can search the log for "ERROR".
--
Paige Miller
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I prefer that program make error and stop execute in such situation. I might miss it by looking at log
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Use the PUTLOG statement to write errors, warning, and notes to the SAS log - The DO Loop
I produce a WARNING for your case ... but you need an input dataset (set statement) in your data step to make it work !
data have;
x=10;
run;
/* The macro %VAREXIST checks to see if a specific variable exists on a specified data set. */
%macro varexist(dsn=class,varname=age);
%local dsid vnum;
%let vnum=0;
%let dsid = %sysfunc(open(&dsn));
%if &dsid %then %do;
%let vnum = %sysfunc(varnum(&dsid,&varname));
%let dsid = %sysfunc(close(&dsid));
%end;
&vnum
%mend varexist;
data want;
set have;
%if %varexist(dsn=have,varname=x)^=0 %then %do;
putlog "NOTE: x-variable is IN input dataset";
%end;
%if %varexist(dsn=have,varname=x) %then %do;
y=x*5;
%end;
run;
data want;
set have;
%if %varexist(dsn=have,varname=z)=0 %then %do;
putlog "WARNING: z-variable NOT IN input dataset";
%end;
%if %varexist(dsn=have,varname=z) %then %do;
y=z*5;
%end;
run;
/* end of program */
Ciao, Koen
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can use the VARINITCHK system option, and set it to ERROR (or WARN if you only want a warning):
1 options varinitchk=error; 2 3 data want; 4 y=z*5; 5 Run; ERROR: Variable z is uninitialized. NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.WANT may be incomplete. When this step was stopped there were 0 observations and 2 variables. WARNING: Data set WORK.WANT was not replaced because this step was stopped.