Returns the name , type, and length of a variable that is used in a DATA step
Category: Variable Information
CALL VNEXT ( varname <, vartype <, varlength >>);
varname
is a character variable that is updated by the CALL VNEXT routine. The following rules apply:
If the input value of varname is blank, the value that is returned in varname is the name of the first variable in the DATA step's list of variables .
If the CALL VNEXT routine is executed for the first time in the DATA step, the value that is returned in varname is the name of the first variable in the DATA step's list of variables.
If neither of the above conditions exists, the input value of varname is ignored. Each time the CALL VNEXT routine is executed, the value that is returned in varname is the name of the next variable in the list.
After the names of all the variables in the DATA step are returned, the value that is returned in varname is blank.
vartype
is a character variable whose input value is ignored. The value that is returned is 'N' or 'C.' The following rules apply:
If the value that is returned in varname is the name of a numeric variable, the value that is returned in vartype is 'N.'
If the value that is returned in varname is the name of a character variable, the value that is returned in vartype is 'C.'
If the value that is returned in varname is blank, the value that is returned in vartype is also blank.
varlength
is a numeric variable. The input value of varlength is ignored.
The value that is returned is the length of the variable whose name is returned in varname . If the value that is returned in varname is blank, the value that is returned in varlength is zero.
The variable names that are returned by the CALL VNEXT routine include automatic variables such as _N_ and _ERROR_. If the DATA step contains a BY statement, the variable names that are returned by CALL VNEXT include the FIRST. variable and LAST. variable names. CALL VNEXT also returns the names of the variables that are used as arguments to CALL VNEXT.
Note: The order in which variable names are returned by CALL VNEXT can vary in different releases of SAS and in different operating environments.
The following example shows the results from using the CALL VNEXT routine.
data test; x=1; y='abc'; z=.; length z 5; run; data attributes; set test; by x; input a b $ c; length name type ; name=' '; length=666; do i=1 to 99 until(name=' '); call vnext(name,type,length); put i= name @40 type= length=; end; this_is_a_long_variable_name=0; datalines; 1 q 3 ;
The following lines are written to the SAS log:
i=1 x type=N length=8 i=2 y type=C length=3 i=3 z type=N length=5 i=4 FIRST.x type=N length=8 i=5 LAST.x type=N length=8 i=6 a type=N length=8 i=7 b type=C length=8 i=8 c type=N length=8 i=9 name type=C length=32 i=10 type type=C length=3 i=11 length type=N length=8 i=12 i type=N length=8 i=13 this_is_a_long_variable_name type=N length=8 i=14 _ERROR_ type=N length=8 i=15 _N_ type=N length=8 i=16 type= length=0