Programming the statistical procedures from SAS

Count distinct values by subjects

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Count distinct values by subjects

[ Edited ]

I have this large data set comprising of over 1000 subjects and about 3000 variables which are ICD9 codes (Dx1- Dx3000). 

Dx represents the ICD diagnosis codes for each visit and is represented here as  1-4

My dataset looks similar to this:

 

 Q.JPG

 

I would like to get the distinct disease count for each subject.

For example: subject 1 has 4 visits but 3 distinct diagnosis.

                      subject 2 has 4 visits and 4 distinct diagnosis

 

Thanks.

 

 


Accepted Solutions
Solution
a month ago
PROC Star
Posts: 1,769

Re: Count distinct values by subjects

1. proc transpose

2. proc freq by id

View solution in original post


All Replies
Solution
a month ago
PROC Star
Posts: 1,769

Re: Count distinct values by subjects

1. proc transpose

2. proc freq by id

Esteemed Advisor
Posts: 5,521

Re: Count distinct values by subjects

proc transpose data=myData out=codes;
by id;
var dx1-dx3000;
run;

proc sql;
create table counts as
select id, count(distinct col1) as nbCodes
from codes
group by id;
quit;

(untested)

 

PG
New Contributor
Posts: 3

Re: Count distinct values by subjects

Thank you so much!! Just what I needed and it worked perfectly well

New Contributor
Posts: 3

Count distinct values by subjects

I have this large data set comprising of over 1000 subjects and about 3000 variables which are ICD9 codes (Dx1- Dx3000). 

Dx represents the ICD diagnosis codes for each visit and is represented here as  1-4

My dataset looks similar to this:

 

 Q.JPG

 

I would like to get the distinct disease count for each subject.

For example: subject 1 has 4 visits but 3 distinct diagnosis.

                      subject 2 has 4 visits and 4 distinct diagnosis

 

Thanks.

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 121 views
  • 0 likes
  • 3 in conversation