Hi everyone,
I'd like to get a count of all the unique cases I have in a dataset. The code I am using is only giving me the counts but not the categories associated with it. Here is my code:
proc sql;
select count(unique(ID)) as u_ID 'Number of Unique Ids'
from MyData
group by Age
;quit;Here are my results:
| Number of Number of Unique Ids |
| 19 |
| 99 |
| 58 |
| 110 |
| 454 |
| 18 |
| 52 |
| 2 |
| 74 |
| 22 |
| 4 |
| 8 |
| 9 |
| 12 |
| 88 |
| 4 |
| 9 |
| 12 |
This is what I would like:
| Age | Number of Number of Unique Ids |
| 0 | 19 |
| 1 | 99 |
| 2 | 58 |
| 3 | 110 |
| 4 | 454 |
| 5 | 18 |
| 6 | 52 |
| 7 | 2 |
| 8 | 74 |
| 9 | 22 |
| 10 | 4 |
| 11 | 8 |
| 12 | 9 |
| 13 | 12 |
| 14 | 88 |
| 15 | 4 |
| 16 | 9 |
| 17 | 12 |
Any advice would be greatly appreciated! Thanks!
Or
proc sql;
select Age, count(unique(ID)) as u_ID 'Number of Unique Ids'
from MyData
group by Age
;quit;
Use PROC FREQ? 🙂
Or
proc sql;
select Age, count(unique(ID)) as u_ID 'Number of Unique Ids'
from MyData
group by Age
;quit;
Hi,
as #draycut proposed you should consider using proc freq.
ods select none;
ods output oneWayFreqs=want(keep=age frequency);
proc freq data=sashelp.class;
table age;
;
run;
ods select all;Cheers
- Cheers -
Actually proc freq can do that. you need NLEVELS option; proc freq ...... nlevels ; ........
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 lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.