Help using Base SAS procedures

data step: Switch off autodeclaration of variables?

Reply
N/A
Posts: 0

data step: Switch off autodeclaration of variables?

Hi together!

The following behaviour is extremly dangerous when working with large databases:

data x_tab;
set y_tab;
if (foo=1) then ...do something;
/* But foo is not defined in y_tab! */
run;

In our SAS configuration you won't get any warning or error about the missing foo-variable. SAS just creates it, sets it to missing and that's it.
Any possibility to prevent the creation and to provoke an error or a warning at least?

Thank you in advance!

Christof
Trusted Advisor
Posts: 2,115

Re: data step: Switch off autodeclaration of variables?

Posted in reply to deleted_user
Not that I am aware of. It has had that feature since version 5 (at least).
Super Contributor
Super Contributor
Posts: 3,174

Re: data step: Switch off autodeclaration of variables?

Posted in reply to deleted_user
Are you sure - did you try the code yourself?

I expect that you should see the SAS LOG message below:

NOTE: Variable foo is uninitialized.

This condition and the associated diagnostic message is SAS working as designed. There have been previous SAS ballot submissions related to this diagnostic and it's note/warning/error degree and also to suppress it, I believe.

Scott Barry
SBBWorks, Inc.
Trusted Advisor
Posts: 2,115

Re: data step: Switch off autodeclaration of variables?

Posted in reply to deleted_user
Scott,

You are right. I have had an occasion with I haven't have the warning, but my CRS is in overdrive today.

You get a note, but not a warning.

data temp;
input a;
cards;
1
run;

DATA; set;
IF foo=1 THEN;
RUN;

NOTE: Variable foo is uninitialized.


Doc
N/A
Posts: 0

Re: data step: Switch off autodeclaration of variables?

Thank you!

Yes, one gets among one of > 1000 notes in a large log file something like at the bottom at least.

No chance to see that if you don't spend half a day just to read every word in your logfile.

The only thing I can conclude:
To train myself into doing searches for 3 words more or less automatically every time I have a look in a log file:
1. "error"
2. "warning"
3. "uninitialized"

Is that common use and knowledge in the SAS user community? Or is there another way to cope with that? By instance a switch or configuration issue to prevent this autodeclarations at all?

Thank you in advance!

Christof








NOTE: SAS initialization used:
real time 0.16 seconds
cpu time 0.08 seconds


NOTE: AUTOEXEC processing beginning; file is /opt/sas/sas9root/autoexec.sas.


NOTE: AUTOEXEC processing completed.

1 data test;
2
3 length x 3.;
4 input x;
5
6 datalines;

NOTE: The data set WORK.TEST has 3 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.02 seconds


10 ;
11 run;
12
13
14 data x;
15 set test;
16 y=0;
17 if (x2=1) then y=1;
18 run;

NOTE: Variable x2 is uninitialized.
NOTE: There were 3 observations read from the data set WORK.TEST.
NOTE: The data set WORK.X has 3 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds


19
20

NOTE: SAS Institute Inc., SAS Campus Drive, Cary, NC USA 27513-2414
NOTE: The SAS System used:
real time 0.71 seconds
cpu time 0.25 seconds

The SAS System
Super Contributor
Super Contributor
Posts: 3,174

Re: data step: Switch off autodeclaration of variables?

Posted in reply to deleted_user
For diagnosing your SAS program, there are other messages in addition to those mentioned, such as one about "...SAS did you a favor and converted a character variable to numeric..." -- sometimes expected but sometimes (in my opinion) not expected, depending on the program DATA step intention.

Best to learn and understand each message type and content as they occur in your SAS experience evolution.

Another nuance with SAS is the lack of any warning/error when a SAS numeric variable is truncated due to a SAS variable LENGTH precision issue - no warning at all given.


Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 5 replies
  • 118 views
  • 0 likes
  • 3 in conversation