/***
TIP00409
    Author: Charles Patridge
     Macro: makeVarList.sas
   Purpose: create a macro variable that contains the list of variables
            within a given sas dataset which are only C=Character or 
            N=Numeric variables
Parameters:
            1st = _sasdsn_ - name of SAS dataset to search through to create macro variable list
            2nd = _type_   - N - create list of NUMERIC   variables
                           - C - create list of CHARACTER variables
    OUTPUT: a macro variables - _VarList_ will contain list of SAS variables which are either
                                Numeric or Character
***/

%macro makeVarList( _sasdsn_=, _type_=N);
  %let _type_ = %upcase( &_type_ );
  %let dsid=%sysfunc(open(&_sasdsn_,i));
  %global _VarList_;
  %let _VarList_=;
  %do i=1 %to %sysfunc(attrn(&dsid,nvars));
  %if (%sysfunc(vartype(&dsid,&i)) = &_type_ ) %then
  %let _VarList_ =&_VarList_ %sysfunc(varname(&dsid,&i));
  %end;
  %let rc=%sysfunc(close(&dsid));
%mend makeVarList;

/*** Sample Call and use of makeVarList ***/
libname  mylib    'c:\download\sas_salary\'; run;
%let mysasfile = mylib.sasalary;
%makeVarList( _sasdsn_=&mysasfile, _type_=C );
%put &_VarList_ ;

%makeVarList( _sasdsn_=&mysasfile, _type_=N );
%put &_VarList_ ;

/*** end of Tip 00409 ***/