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;
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.
What is the problem here? You can search the log for "uninitialized", just like you can search the log for "ERROR".
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
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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.