|
6#
楼主 |
发表于 2003-10-30 16:51:58
|
只看该作者
/* MACRO varlist: Gets the names of the numerical , dateformat and character variables
from a dataset and writes them to macro variables.
Input: Data_in = Name of input dataset
Outputs: numlist = Macro variable of numerical variable names
datelist = Macro variable of dateformat variable names
charlist = Macro variable of character variable names
*/
%MACRO varlist(DATA_IN);
%global numlist datelist charlist;
* Get Contents;
proc contents data=&data_in out=temp1 noprint;
run;
*Create data set nums that contains only the names of the numerical but not date vbles;
data nums(keep=name label);
set temp1(keep=name type label format);
if type=1 and format ne 'DATE';
run;
* Put each name in a macro vble, get number of vbles;
data _null_;
set nums;
call symput('NN'||left(put(_n_,10.)),left(put(name,$9.)));
call symput('numnums',_n_);
run;
* Concatenate the vble names;
%do i=1 %to &numnums;
%if &i=1 %then %let numlist = &&NN&i;
%else %let numlist = &numlist &&NN&i;
%end;
%put => The list of numerical vbles is: &numlist;
*Create data set nums that contains only the names of the date vbles;
data dats(keep=name label);
set temp1(keep=name type label format);
if type=1 and format eq 'DATE';
run;
* Put each name in a macro vble, get number of vbles;
data _null_;
set dats;
call symput('DD'||left(put(_n_,10.)),left(put(name,$9.)));
call symput('numdats',_n_);
run;
* Concatenate the vble names;
%do i=1 %to &numdats;
%if &i=1 %then %let datelist = &&DD&i;
%else %let &datelist = &datelist &&DD&i;
%end;
%put => The list of date format vbles is: &datelist;
*Create data set chars that contains only the names of the char vbles;
data chars(keep=name label);
set temp1(keep=name type label);
if type=2;
run;
* Put each name in a macro vble, get number of vbles;
data _null_;
set chars;
call symput('DD'||left(put(_n_,10.)),left(put(name,$9.)));
call symput('numchars',_n_);
run;
* Concatenate the vble names;
%do i=1 %to &numchars;
%if &i=1 %then %let charlist = &&DD&i;
%else %let charlist = &charlist &&DD&i;
%end;
%put => The list of character vbles is: &charlist;
proc datasets library =WORK nolist;
delete nums chars dats temp1;
run;
%MEND varlist; |
|