Previous Page | Next Page

SAS Component Language Dictionary

VARLEVEL



Reports the unique values of a SAS table column
Category: Variable

Syntax
Details
Example
See Also

Syntax

rc=VARLEVEL(array-name,n-level,table-id,var-name);

rc

contains the return code for the operation:

0

successful

[ne]0

not successful

Type: Numeric

array-name

is the array that will contain the unique column values. This should be a character array with an element size that is large enough to hold the longest value. VARLEVEL assigns to array items the unique values of the SAS table column var-name.

Type: Character

n-level

is the name of the variable in which the function stores the number of unique values (or levels). This variable must be initialized to a nonmissing value before its value is set by the VARLEVEL function.

Note:   This parameter is an update parameter. See Input, Output, and Update Parameters for more information.  [cautionend]

Type: Numeric

table-id

is the identifier that was assigned when the table was opened. If table-id is invalid, the program halts.

Type: Numeric

var-name

is the column for which unique values are to be returned.

Type: Character


Details

VARLEVEL fills the array array-name with the unique values of the SAS table column var-name.

This function returns values to the specified array. It also returns the total number of unique values in the n-level argument. Therefore, the second argument to this function cannot be a literal. If the number of unique values found exceeds the dimension of the array, the function returns only DIM(array-name) levels. That is, VARLEVEL requires the static allocation of an array that is big enough to hold all the unique values.

LVARLEVEL provides the same functionality, but it stores the unique values in an SCL list rather than an array. Because an SCL list can grow dynamically, you should consider using it rather than VARLEVEL.


Example

Get the unique formatted values for the table column X. Use ASORT to sort those values in ascending order. If NLEVELS is greater than 25, then only the first 25 values are written to the array.

array values {25} $ 20;
tableid=open('mylib.data','i');
nlevels=0;
rc=varlevel(values,nlevels,tableid,'x');
rc=asort(values);
do i=1 to dim(values);
   put values(i);
end;
rc=close(tableid);


See Also

LVARLEVEL

VARNAME

VARSTAT

Previous Page | Next Page | Top of Page