1.4 - SAS Variables

1.4 - SAS Variables

One thing you might have noticed about our data set:

ID Name Height Weight

53

Susie 65 120
54 Charles 72 200
55   60 105
56 Lucy 63 142
57 Dennis 70 .

is that there are two different types of variables — there are three numeric variables (ID, height, and weight) and one character variable (name). The type of variable is just one of six variable attributes that SAS stores in the descriptor portion of every SAS data set. The six attributes that SAS stores are:

  • the variable's name
  • the variable's type
  • the variable's length
  • the variable's format (if any)
  • the variable's informat (if any)
  • and the variable's label (if any)

As suggested by the presence of the ("if any") phrase in the above list, an informat, format, and label do not exist for every variable. A name, type, and length, on the other hand, do exist for every variable. The following is a partial listing of what might be the attribute information in the descriptor portion of our SAS data set:

Alphabetic List of variables and Attributes
Variable Type Len Format Label
height Num 8 4.1 Height (inches)
id Num 8    
name Char 7    
Weight Num 8 5.1 Weight (pounds)

Let's investigate each of the six attributes briefly.

Variable names. There's not much more to say about a variable's name that hasn't already been said on the SAS basics page. That is, as long as your variable names conform to SAS naming conventions, you're good to go. In case you haven't memorized it yet, variable names must be between 1 and 32 characters long, must begin with either an uppercase letter, lowercase letter or an underscore (_), and thereafter can contain any combination of numbers, letters, or underscores.

Variable types. As mentioned earlier, a variable is either identified as being character or numeric. Character variables, such as name, can contain any character that you can make with your keyboard (letters, numbers, !@#$%^&( )_+, ... you get the idea). Numeric variables, on the other hand, such as id, height, and weight, can contain only numeric values — namely, the digits 0 through 9, a positive sign (+), a negative sign (-), a decimal place (.), and the capital letter E for scientific notation.

Another thing you might have noticed about our data set above is that some information in the data set is missing — the name of the person whose ID is 55 is missing, and the weight of Dennis is missing. That's okay — SAS can handle missing data. What SAS displays when a value is missing depends on the variable's type. As suggested by the above data set, SAS displays a blank space for a missing character value and a period (.) for a missing numeric value.

Variable length. A variable's length tells us how many bytes are used to store the variable in your computer's memory. Character variables can be up to 32,767 bytes long. In our data set, the variable name has a length of 7 characters and therefore uses 7 bytes of storage. All numeric variables have a default length of 8. Numeric values (no matter how many digits they contain) are stored as floating-point numbers in 8 bytes of storage, unless you specify a different length. It shouldn't be surprising therefore that the length of each of the numeric variables in our data set is 8.

Variable formats and informats. We'll learn about these two attributes in greater detail later in the course. For now, just know that a variable's format tells SAS how you'd like your variable's values displayed in reports. For example, you might want to tell SAS to display the value 5391 as $5391.00 or maybe 5,391 instead. Whereas formats tell SAS how to write a variable's values, informats tell SAS how to read data values having a special form into standard SAS values.

Variable labels. If you want, you can give your variables descriptive labels up to 256 characters long. By default, many of the standard reports in SAS identify variables by their names. You can instead tell SAS to display more descriptive information about the variable by assigning a label to the variable. In our data set above, the variables height and weight were given the more descriptive labels of "Height (inches)" and "Weight (pounds)", respectively.

That's about all you need to know about SAS variables for now! Let's now delve into how to interact with the SAS Windowing Environment, so we can first write and then run some SAS programs.


Legend
[1]Link
Has Tooltip/Popover
 Toggleable Visibility