VARLEN Function

Returns the length of a SAS data set variable.

Category: SAS File I/O

Syntax

Required Arguments

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.

Tips This number is next to the variable in the list that is produced by the CONTENTS procedure.
The VARNUM function returns this number.

Details

VLENGTH returns the compile-time (allocated) size of the given variable.

Example

  • 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;

See Also