Hi I am thinking is it possible to count distinct combination of two variables, for example:
I know proc sql;
count(distinct (variable))
but it only count base on one criteria...
| person_ID | condition_Id |
| 1 | 1 |
| 1 | 2 |
| 1 | 1 |
| 2 | 2 |
| 3 | 1 |
| 3 | 1 |
| 4 | 2 |
| 4 | 1 |
| 4 | 2 |
| 5 | 1 |
| 5 | 2 |
| 6 | 1 |
this should give me a count of 9 (person 1 was count twice although it has 3 entries, person 3 count only 1 although it has 2 entries).
All ideas are welcome!
Distinct can also be used at the row level:
data test;
input person_ID condition_Id ;
datalines;
1 1
1 2
1 1
2 2
3 1
3 1
4 2
4 1
4 2
5 1
5 2
6 1
;
proc sql;
select count(*) as n
from
(select distinct person_id, condition_id
from test);
quit;
Distinct can also be used at the row level:
data test;
input person_ID condition_Id ;
datalines;
1 1
1 2
1 1
2 2
3 1
3 1
4 2
4 1
4 2
5 1
5 2
6 1
;
proc sql;
select count(*) as n
from
(select distinct person_id, condition_id
from test);
quit;
The SQL gurus may shoot me over this, but as long as both variables are numeric you could use:
proc sql;
select count (distinct(person_ID + condition_ID/10)) from have;
quit;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.