8.5 - Variable Not Found

8.5 - Variable Not Found

This section illustrates the kinds of messages you might see in the log window when you have misspecified a variable name somewhere in your program.

Example 8.9

The following example illustrates the "Note: Variable is uninitialized" and "Error: Variable not found" messages SAS displays in the log window to warn you of such problems:

OPTIONS PS = 58 LS = 72 NODATE NONUMBER;

DATA trees;
    input type $ 1-16 circ_in hght_ft crown_ft;
	volume = (0.319*hght)*(0.0000163*circ_in**2);
	DATALINES;
oak, black        222 105 112
hemlock, eastern  149 138  52
ash, white        258  80  70
cherry, black     187  91  75
maple, red        210  99  74
elm, american     229 127 104
;
RUN;

PROC PRINT data = trees;
    var type height circ_in volume;
RUN;

First, note that there are two places in which a variable name was misspecified in this program. In the calculation of volume in the DATA step, the height of the tree is referred to as hght rather than hght_ft in which the heights were actually stored. And, in the PRINT procedure, the height of the tree is referred to as height. Well, okay, so the programmer, is a little confused! Launch and run the SAS program, and review the log window to see the two messages that SAS displays in this situation.

Common ways to "lose" variables include:

  • misspelling a variable name
  • using a variable that was dropped from the data set at some earlier time
  • using the wrong data set
  • committing a logic error, such as using a variable before it is created

If the source of the problem is not immediately obvious, submitting a CONTENTS procedure can often help you sniff out the problem. As you may recall from an earlier lesson, the CONTENTS procedure provides, among other things, the names of the variables contained in a SAS data set.


Legend
[1]Link
Has Tooltip/Popover
 Toggleable Visibility