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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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