Functions and CALL Routines |
Returns the number of a variable's position in a SAS data set.
VARNUM(data-set-id,var-name)
|
-
data-set-id
-
specifies the data set identifier that the
OPEN function returns.
-
var-name
-
specifies the variable's name.
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.
-
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.
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;
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.