BookmarkSubscribeRSS Feed
bhca60
Quartz | Level 8

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?

2 REPLIES 2
CarmineVerrell
SAS Employee

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;

 

ballardw
Super User

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 921 views
  • 0 likes
  • 3 in conversation