Trying to create a table that displays the most frequent ndc# for a given patient(pat_seqno). My having clause have not worked thus far and this is my most recent attempt, which returns an error that ndc_count is not found in the contributing tables. Thanks for the help
proc sql;
create table unique_rx_count as
select pat_seqno , ndc_seqno, ndc_count
from d1
where ndc_seqno in
(select count(ndc_seqno) as ndc_count
from d1
group by pat_seqno)
group by pat_seqno
having ndc_count = max(ndc_count)
;
quit;
example: Pat_seqno ndc_seqno 2 45 2 45 2 23 2 45 16 10 16 10 16 78
return expected Pat_seqno ndc_seqno 2 45 16 10