Functions and CALL Routines |
Returns the length of a SAS data set variable.
VARLEN(data-set-id,var-num)
|
-
data-set-id
-
specifies the data set identifier that the
OPEN function returns.
-
var-num
-
specifies the number of the variable's position
in the SAS data set.
Tip: |
This number is next to the
variable in the list that is produced by the CONTENTS procedure. |
Tip: |
The VARNUM function returns
this number. |
VLENGTH returns the compile-time (allocated) size of the given
variable.
-
This example obtains the length of the variable
ADDRESS in the SAS data set MYDATA.
%let dsid=%sysfunc(open(mydata,i));
%if &dsid %then
%do;
%let len=%sysfunc(varlen(&dsid,
%sysfunc(varnum
(&dsid,ADDRESS))));
%let rc=%sysfunc(close(&dsid));
%end;
-
This example creates a data set that contains
the name, type, and length of the variables in MYDATA.
data vars;
length name $ 8 type $ 1;
drop dsid i num rc;
dsid=open("mydata","i");
num=attrn(dsid,"nvars");
do i=1 to num;
name=varname(dsid,i);
type=vartype(dsid,i);
length=varlen(dsid,i);
output;
end;
rc=close(dsid);
run;
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.