I would like your help (or other advice) how to do this.
I have a long list of numeric and character variables to tabulate. Very easy. Very tedious.
I believe I can run a macro, similar to the one below (which doesn't work, by the way), to determine if the variable is NUMERIC or CHARACTER, and then direct it to the appropriate macro.
1) Can you assist with the macro?
2) If not, thoughts on how this obviously common task can be done would be appreciated.
🙂
------------------------------------------------------------
DATA CARS;
SET SASHELP.CARS;
RUN;
%macro TEMP(all_vars=);
%let k=1;
%let var = %scan(&all_vars, &k);
%do %until(&var eq "END");
%if (%datatyp(&var)=NUMERIC ) %then %do;
%TABLECONT(DATA= CARS,BYVAR= ORIGIN,VAR=&var.);
%end;
%else %do;
%TABLECHAR(DATA= CARS,BYVAR= ORIGIN,VAR=&var.);
%end;
%let k = %eval(&k + 1);
%let VAR = %scan(&all_vars, &k);
%end;
%mend temp;
%MACRO TABLECHAR(DATA= CARS,BYVAR= ORIGIN,VAR=);
proc TABULATE DATA=CARS;
class &var ORIGIN ;
TABLE (&VAR ALL),(ORIGIN ALL) *(N="n" COLpctn= "%"*F=5.1);
RUN;
%mend TABLECHAR;
%MACRO TABLECONT (DATA= CARS,BYVAR= ORIGIN,VAR=);
PROC TABULATE DATA=CARS ;
class origin;
var &var;
TABLE (&VAR ),(ORIGIN ALL)
*(N="n" mean='Mean'*F=8.1);
RUN;
%MEND TABLECONT;
%temp(ALL_vars=cylinders type weight msrp END);
: Example with SASHELP.CARS now included.
[If you run it, you will have to manually cancel the submitted statements because DO WHILE is not working]
... View more