I am trying to get the number of diagnoses per ID and grab only those with 2 or less:
proc sql;
create table diagcount as
select
claimheaderid,
dxSeqNo,
count(icd) as diagct
from denomip
group by claimheaderid, dxSeqno;
run;
/*less than or equal to 2 dx codes per claimheaderid*/
data diagct;
set diagcount;
by claimHeaderId;
where diagct <=2;
run;
Am I on the right track?
Next time please include a data example as i have included. Seem like the code is working fine. see below
also you could get rid of the data step procedure and include this line in your sql .
where calculated diagct < 2; (hint- in-between the from and the group by)
data denomip ;
input claimheaderid dxSeqNo icd ;
datalines ;
10 3 1
40 1 2
40 1 2
40 2 2
10 1 2
10 3 2
10 2 2
40 1 3
40 3 3
40 2 3
;
run;
proc sql;
create table diagcount as
select
claimheaderid,
dxSeqNo,
count(icd) as diagct
from denomip
group by claimheaderid, dxSeqno;
run;
/*less than or equal to 2 dx codes per claimheaderid*/
data diagct;
set diagcount;
by claimHeaderId;
where diagct <=2;
run;
Your SQL is counting by ID AND Dxseqno. That does not match your description of counting the number of diagnoses.
Does the SQL give what you expect?
My guess is that you may not want the Dxseqno in that counting as you will get separate count for ID=1 and DXseqno=1, Id=1 and Dxseqno=2, Id=1 and Dxseqno=3. If there exactly 3 observations for Id=1 that look like that list and you expect a count to be 3 then you want to remove Dxseqno from the Group by and the Select.
Provide some example data and expected result for that small sample.
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.