BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hwangnyc
Quartz | Level 8

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:

 

AgeNumber of Number of Unique Ids
019
199
258
3110
4454
518
652
72
874
922
104
118
129
1312
1488
154
169
1712

 

Any advice would be greatly appreciated! Thanks! 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Or

 

proc sql;
 select Age, count(unique(ID)) as u_ID 'Number of Unique Ids'
 from MyData
 group by Age
;quit;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Use PROC FREQ? 🙂

PeterClemmensen
Tourmaline | Level 20

Or

 

proc sql;
 select Age, count(unique(ID)) as u_ID 'Number of Unique Ids'
 from MyData
 group by Age
;quit;
Oligolas
Barite | Level 11

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 -

hwangnyc
Quartz | Level 8
Thanks for the response, proc freq would not work because I wanted the unique cases. Proc freq could give me the frequency for all cases.
Ksharp
Super User
Actually proc freq can do that. you need NLEVELS option;

proc freq ......    nlevels ;
........

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

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
  • 5 replies
  • 2411 views
  • 1 like
  • 4 in conversation