Namrata, This should do what you want: For reference I nested the creation of the sum variables in the joins in testb, but this could just as easily be done in two separate tables and then joined in, in the same manner. I maxed the values in testa bc you only wanted the best value for duplicates. Hope this helps. proc sql; create table testa as select distinct year, firm, industry, (max(value)) as value, (case when (max(value)) >0 then 'A' else 'N' end) as status from test group by year, firm, industry; create table testb as select distinct a.*, b.acount, c.numfirm from testa a left join (select distinct year, firm, industry, (sum(case when status = 'A' then 1 else 0 end)) as acount from testa group by year, firm, industry) b on (a.year=b.year and a.firm=b.firm and a.industry=b.industry) left join (select distinct year, count(firm) as numfirm, industry from testa group by year, industry) c on (a.year=c.year and a.industry=c.industry); quit;
... View more