Functions and CALL Routines |
Returns the name of a SAS data set variable.
VARNAME(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. |
This example copies the names of the first five variables
in the SAS data set CITY (or all of the variables if there are fewer than
five) into a macro variable.
%macro names;
%let dsid=%sysfunc(open(city,i));
%let varlist=;
%do i=1 %to
%sysfunc(min(5,%sysfunc(attrn
(&dsid,nvars))));
%let varlist=&varlist %sysfunc(varname
(&dsid,&i));
%end;
%put varlist=&varlist;
%mend names;
%names
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.