Functions and CALL Routines |
Returns the value of a SAS data set character variable.
GETVARC(data-set-id,var-num)
|
-
data-set-id
-
is a numeric constant, variable, or expression
that specifies the data set identifier that the OPEN function returns.
-
var-num
-
is a numeric constant, variable, or expression
that specifies the number of the variable in the Data Set Data
Vector (DDV).
Tip: |
You can obtain this value
by using the VARNUM function. |
Tip: |
This value is listed next
to the variable when you use the CONTENTS procedure. |
Use VARNUM to obtain the number of a variable
in a SAS data set. VARNUM can be nested or it can be assigned to a variable
that can then be passed as the second argument, as shown in the following
examples. GETVARC reads the value of a character variable from the current
observation in the Data Set Data Vector (DDV) into a macro or DATA step variable.
-
This example opens the SASUSER.HOUSES data set
and gets the entire tenth observation. The data set identifier value for the
open data set is stored in the macro variable MYDATAID. This example nests
VARNUM to return the position of the variable in the DDV, and reads in the
value of the character variable STYLE.
%let mydataid=%sysfunc(open
(sasuser.houses,i));
%let rc=%sysfunc(fetchobs(&mydataid,10));
%let style=%sysfunc(getvarc(&mydataid,
%sysfunc(varnum
(&mydataid,STYLE))));
%let rc=%sysfunc(close(&mydataid));
-
This example assigns VARNUM to a variable that
can then be passed as the second argument. This example fetches data from
observation 10.
%let namenum=%sysfunc(varnum(&mydataid,NAME));
%let rc=%sysfunc(fetchobs(&mydataid,10));
%let user=%sysfunc(getvarc
(&mydataid,&namenum));
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.