Previous Page | Next Page

Functions and CALL Routines

VARFMT Function



Returns the format that is assigned to a SAS data set variable.
Category: SAS File I/O

Syntax
Arguments
Details
Examples
Example 1: Using VARFMT to Obtain the Format of the Variable NAME
Example 2: Using VARFMT to Obtain the Format of all the Numeric Variables in a Data Set
See Also

Syntax

VARFMT(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

If no format has been assigned to the variable, a blank string is returned.


Examples


Example 1: Using VARFMT to Obtain the Format of the Variable NAME

This example obtains the format of the variable NAME in the SAS data set MYDATA.

%let dsid=%sysfunc(open(mydata,i));
%if &dsid %then
   %do;
      %let fmt=%sysfunc(varfmt(&dsid,
                        %sysfunc(varnum
                        (&dsid,NAME))));
      %let rc=%sysfunc(close(&dsid));
   %end;


Example 2: Using VARFMT to Obtain the Format of all the Numeric Variables in a Data Set

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

data vars;
   length name $ 8 content $ 12;
   drop dsid i num rc fmt;
   dsid=open("mydata","i");
   num=attrn(dsid,"nvars");
   do while (fetch(dsid)=0);
      do i=1 to num;
         name=varname(dsid,i);
         if (vartype(dsid,i)='N') then do;
            fmt=varfmt(dsid,i);
            if fmt='' then fmt="BEST12.";
            content=putc(putn(getvarn
                        (dsid,i),fmt),"$char12.");
            output;
            end;
      end;
   end;
   rc=close(dsid);
run;


See Also

Functions:

VARINFMT Function

VARNUM Function

Previous Page | Next Page | Top of Page