SAS Component Language Dictionary |
Category: | Variable |
Syntax | |
Details | |
Example | |
See Also |
Syntax |
rc=VARLEVEL(array-name,n-level,table-id,var-name); |
contains the return code for the operation:
0 | |
0 |
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.
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.
is the identifier that was assigned when the table was opened. If table-id is invalid, the program halts.
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 |
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.