Then Try this one: proc sql; create table want (rename=(trandate_m=trandate subregion_m=subregion)) as select a.id, count(distinct a.id) as ID_CT, (select count(distinct id) from (select id from have group by id having count(distinct region)>1))as id_ct_r, (select count (distinct id) from (select id, distinct region from have group by id, region having count(distinct subregion)>1)) as id_ct_sr, calculated id_ct_r / calculated id_ct as percent_R format percent7.2, calculated id_ct_sr / calculated id_ct as percent_SR format percent7.2, b.trandate_m, b.subregion_m from have a left join (select id, subregion as subregion_m, max(trandate) as trandate_m format yymmdd10. from have group by id having trandate=calculated trandate_m) b on a.id=b.id ; quit; And plesae let us know how it works for you, Regards, Haikuo
... View more