-
Notifications
You must be signed in to change notification settings - Fork 21
/
descrp_stats_byvar.sas
40 lines (31 loc) · 965 Bytes
/
descrp_stats_byvar.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
** Note this is from the Accounting Group Macros.sas file, also included in its entirety;
/***************************************************
Descriptive Statistics by groups
You can group by more than one variable,just separate by spaces
ex: %descr_by(dset=mydata, byvar=year industry, vars=assets earnings, stats=n mean median);
***************************************************/
%macro descr_by(dset=,byvar=,vars=,stats=n mean min p1 q1 median q3 p99 max);
%let j=1;
%do %until ( %scan(&vars,&j)= );
%let var&j = %scan(&vars,&j);
%let j=%EVAL(&j+1);
%end;
proc sort data=&dset out=xtemp;
by &byvar;
run;
ods listing close;
proc means data=xtemp &stats;
by &byvar;
var &vars;
ods output Summary = xout;
run;
ods listing;
%do k = 1 %to %EVAL(&j-1);
%let base = &&var&k;
proc print data=xout noobs;
var &byvar &base._:;
format &base._: 10.4;
format &base._N comma10.0;
run;
%end;
%mend descr_by;