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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 526 views
  • 0 likes
  • 3 in conversation