VARNUM Function

Returns the number of a variable's position in a SAS data set.

Category: SAS File I/O

Syntax

Required Arguments

data-set-id

specifies the data set identifier that the OPEN function returns.

var-name

specifies the variable's name.

Details

VARNUM returns the number of a variable's position in a SAS data set, or 0 if the variable is not in the SAS data set. This is the same variable number that is next to the variable in the output from PROC CONTENTS.

Example

  • This example obtains the number of a variable's position in the SAS data set CITY, given the name of the variable.
    %let dsid=%sysfunc(open(city,i));
    %let citynum=%sysfunc(varnum(&dsid,CITYNAME));
    %let rc=%sysfunc(fetch(&dsid));
    %let cityname=%sysfunc(getvarc
                          (&dsid,&citynum));
  • This example creates a data set that contains the name, type, format, informat, label, length, and position of the variables in SASUSER.HOUSES.
    /* Tested 2/27/98 — OK */
    %INCLUDE '/local/u/lirezn/sasuser/assist.src';
    data vars;
       length name $ 8 type $ 1 
              format informat $ 10 label $ 40;
       drop dsid i num rc;
       dsid=open("sasuser.houses","i");
       num=attrn(dsid,"nvars");
       do i=1 to num;
          name=varname(dsid,i);
          type=vartype(dsid,i);
          format=varfmt(dsid,i);
          informat=varinfmt(dsid,i);
          label=varlabel(dsid,i);
          length=varlen(dsid,i);
          position=varnum(dsid,name);
          output;
       end;
       rc=close(dsid);
    run;

See Also