/*罗伦兹曲线与gini系数*/
data taxf;
infile 'B:\SAS培训\taxf.txt';
input TIncome TTax RCode;
label TIncome='总收入';
label TTax='总纳税额';
label RCode='注册类型';
run;
data taxf;
set taxf;
if tincome =. then delete;
label rcode="code for register";
run;
proc gchart data=taxf;
vbar tincome;
pie rcode;
run;
proc gplot ;
plot ttax*tincome;
run;
data a;
SET taxf;
proc sort;
by descending tincome;
run;
data a;
set a;
retain m 0;/*按照收入由高到底的顺序逐步汇总总收入*/
retain n 0;
m=m+tincome; n=n+ttax;id=_n_;
run;
proc sort data=a;
BY descending id;
run;
data b;
set a;
retain total_m total_n;
if _n_=1 then do total_m=m; total_n=n;end;
percent_i=m/total_m;
percent_t=n/total_n;
p=percent_i;
run;
proc sort data=b;
by percent_i;
run;
proc gplot data=b;
symbol i=join v=none line=1 width=2;/*color是数据线的颜色,i表示是否连接,v表示数据点用不用特殊符号标记,L表示线型,WIDTH表示数据线的厚度*/
plot (percent_i )* (percent_t p)/overlay;
run;
proc sql;
select sum(percent_t-percent_i)/sum(percent_t)
from b;
quit;