/* VARNUM Function returns the number of a variable's */
/* position in a SAS data set */
/* Syntax */
/* VARNUM(data-set-id,var-name) */
/* where data-set-id specifies the data set identifier */
/* that the OPEN function returns, var-name specifies */
/* the variable's name. */
data vars;
length name $ 8 type $ 1
format informat $ 10 label $ 40;
drop dsid i num rc;
dsid=open("sashelp.prdsale","i");
num=attrn(dsid,"nvars");
do i=1 to num;
name=varname(dsid,i);
type=vartype(dsid,i);
position=varnum(dsid,name);
output;
end;
rc=close(dsid);
run;