VARTYPE Function


Returns the data type of a SAS data set variable

Category: SAS File I/O

Syntax

VARTYPE ( data-set-id , var-num )

Arguments

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.

Details

VARTYPE returns C for a character variable or N for a numeric variable.

Examples

Example 1: Using VARTYPE to Determine which Variables are Numeric

This example places the names of all the numeric variables of the SAS data set MYDATA into a macro variable.

 %let dsid=%sysfunc(open(mydata,i));  %let varlist=;  %do i=1 %to %sysfunc(attrn(&dsid,nvars));     %if (%sysfunc(vartype(&dsid,&i)) = N) %then        %let varlist=&varlist %sysfunc(varname                                    (&dsid,&i));  %end;  %let rc=%sysfunc(close(&dsid)); 

Example 2: Using VARTYPE to Determine which Variables are Character

This example creates a data set that contains the name and formatted contents of each character variable in the SAS data set MYDATA.

 data vars;     length name $ 8 content $ 20;     drop dsid i num fmt rc;     dsid=open("mydata","i");     num=attrn(dsid,"nvars");     do while (fetch(dsid)=0);        do i=1 to num;        name=varname(dsid,i);        fmt=varfmt(dsid,i);        if (vartype(dsid,i)='C') then do;           content=getvarc(dsid,i);           if (fmt ne " ) then            content=left(putc(content,fmt));           output;           end;        end;     end;     rc=close(dsid);  run; 

See Also

Function:

  • 'VARNUM Function' on page 877




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net