Hello @kevsma,
You can create a small auxiliary dataset which just contains all values of ETH. If all these values occur in the unrestricted dataset &Regctr., the preliminary step could look like this:
proc sql;
create table alleth as
select distinct eth from &Regctr.;
quit;
Otherwise INSERT additional ETH values into this dataset.
Then use the complete ALLETH dataset, e.g., in a RIGHT JOIN:
proc sql;
create table tbl26 as
select a.eth,
count(distinct case when(amt=0) then uci end) as nopos,
count(distinct case when(amt>0) then uci end) as yespos,
count(distinct uci) as totcnt,
coalesce(calculated nopos/calculated totcnt,0) as share
from ®ctr.(where=(age='00-02')) natural right join alleth a
group by a.eth
union all
select 'z',
count(distinct case when(amt=0) then uci end) as nopos,
count(distinct case when(amt>0) then uci end) as yespos,
count(distinct uci) as totcnt,
calculated nopos/calculated totcnt as share
from ®ctr.(where=(age='00-02'));
quit;
The COALESCE function can be omitted if you accept SHARE=. for the 0/0 case.
Note that I have corrected a mistake in your second SELECT statement: Without the CORR keyword of the UNION operator the variables would be matched by ordinal position, so with your code TOTCNT from the second SELECT would be matched with NOPOS from the first SELECT, NOPOS with YESPOS and so on! Alternatively (more robust), use the CORR keyword:
union all corr
select 'z' as eth,
... View more