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

How do you count the number of subjects in a big dataset? Each subject has serval records , is there a way to find the number of subjects in the dataset?

1 ACCEPTED SOLUTION

Accepted Solutions
PhilC
Rhodochrosite | Level 12

Take for instance the example data set SASHELP.SHOES.  Imagine that the region column identifies your subjects.  Then...

PROC SQL;
   SELECT COUNT(DISTINCT(Region))) AS COUNT_DISTINCT_of_Region
      FROM SASHELP.SHOES ;
QUIT;

We find with this that there are 10 regions (or imagined subjects). 

 

Related article: Your data ain't good looking, but it has a nice cardinality - The SAS Dummy

 

View solution in original post

2 REPLIES 2
PhilC
Rhodochrosite | Level 12

Take for instance the example data set SASHELP.SHOES.  Imagine that the region column identifies your subjects.  Then...

PROC SQL;
   SELECT COUNT(DISTINCT(Region))) AS COUNT_DISTINCT_of_Region
      FROM SASHELP.SHOES ;
QUIT;

We find with this that there are 10 regions (or imagined subjects). 

 

Related article: Your data ain't good looking, but it has a nice cardinality - The SAS Dummy

 

Reeza
Super User
Define big.

If you get really, really big, you may want a hash solution. Otherwise, here are two ways to find the distinct counts;
https://github.com/statgeek/SAS-Tutorials/blob/master/count_distinct_by_group.sas

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

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