dataset is from post [疑难解惑] 海外学生学习sas遇到瓶颈 分类汇总
https://bbs.pinggu.org/forum.php? ... =2883292&page=1- /* using array */
- proc sql noprint;
- select distinct income, count(distinct income)
- into :disincome separated by ' ',
- :nl
- from regdiet;
- quit;
- data rate;
- array income_{&nl} _temporary_ (&disincome);
- array TShopper{&nl};
- array TCouponUsed{&nl};
- set regdiet (keep= income coupuse) end=last;
- do i = 1 to &nl;
- if income = income_ [i] then do;
- Tshopper[i] +1;
- TCouponused[i] ++ coupuse;
- end;
- end;
- if last then do;
- do i = 1 to &nl;
- incomeLevel = income_[i];
- TotalShopper = Tshopper[i];
- TotalCouponUsed = TCouponused[i];
- CouponUseRate = TotalCouponUsed / TotalShopper;
- output;
- end;
- end;
- keep incomelevel TotalShopper TotalCouponUsed CouponUseRate;
- run;
复制代码