As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.


Here are some tips for How to share your SAS knowledge with your professional network.


SAS Variable Lists

From sasCommunity
Jump to: navigation, search

It can be very tedious to specify a long list of variables, so SAS has variable lists that you can use specify for 'special' variables. Below are the variable lists that are available in SAS.

Numbered Range Lists

Numbered range lists require you to have a series of variables with the same name, except for the last character or characters, which are consecutive numbers.

For example,

If you want to refer to this group of variables:

Revenue01, Revenue02, Revenue03, Revenue04, Revenue05, Revenue06

you can use the list below to refer to the same group:

Revenue01-Revenue06

In a numbered range lists, you can begin with any number and end with any number as long as the numbers are consecutive.

Name Range Lists

Name Range lists allow SAS Users to specify all the variables that are between x to a (inclusive) in the Program Data Vector. You can also specify all the numeric/character variables in between x to a inclusive. Please see table below.

Name Range Lists
Variable List Description
x--a Specify all the variables that are between x to a (inclusive) in the Program Data Vector.
x-numeric-a Specify all the numeric variables that are between x to a (inclusive) in the Program Data Vector.
x-character-a Specify all the character variables that are between x to a (inclusive) in the Program Data Vector.

Be careful when using name range lists. Most SAS programmers do not usually pay attention to the variable order on the PDV, and there can be inadvertent changes to the order that will cause the variables returned by these lists to change.

Name Prefix Lists

Some SAS functions and statements enable you to use a Name Prefix List to refer to ALL variables that begin with a specified character string:

 min(of Costs:)

tells SAS to calculate the minimum of all the variables that begin with "Costs," such as Costs_JAN, Costs_FEB, and Costs_MAR.

Special SAS Name Lists

Special SAS name lists include

Special SAS Name Lists
Variable List Description
_NUMERIC_ specifies all numeric variables that are already defined in the current DATA step.
_CHARACTER_ specifies all character variables that are currently defined in the current DATA step.
_ALL_ specifies all variables that are currently defined in the current DATA step.

Array References

Most functions that accept a list of variables will now accept an array reference.

call missing(of numlist{*});

Although SAS Variable lists provide great shortcuts to specify the variables that you need, it would be better that one does a PROC Contents on the dataset in question in order to have a better understanding of the variables and their order.

See also