## Counting the number of distinct values of a variable

Solved
Occasional Contributor
Posts: 18

# Counting the number of distinct values of a variable

What's the most efficient way to count the no. of distinct values of a particular variable in SAS EG? Google brings up the Data Exploration tool, but it seems to only work for datasets that aren't already in the SAS project. The dataset that I want to count is in the WORK library and is a product of a table join by the query builder.

Thank you!

Accepted Solutions
Solution
‎05-11-2014 02:22 PM
Super User
Posts: 23,980

## Re: Counting the number of distinct values of a variable

If you only want EG then I suggest the summarize task twice. First time will get you the different counts of each level, the second will count the number of levels.

A different way is through a QUERY using count Distinct as a calculated variable.

All Replies
Super User
Posts: 23,980

## Re: Counting the number of distinct values of a variable

Proc Freq nlevels option is the fastest that I know.

Occasional Contributor
Posts: 18

## Re: Counting the number of distinct values of a variable

Is that available as a task in EG? I meant a method specific to the UI in EG, if possible.

Solution
‎05-11-2014 02:22 PM
Super User
Posts: 23,980

## Re: Counting the number of distinct values of a variable

If you only want EG then I suggest the summarize task twice. First time will get you the different counts of each level, the second will count the number of levels.

A different way is through a QUERY using count Distinct as a calculated variable.

Community Manager
Posts: 3,452

## Re: Counting the number of distinct values of a variable

There is a custom task that you can download.  It calculates the cardinality -- or number of distinct levels -- of each variable in your data set.

The UI looks like this:

Chris

Occasional Contributor
Posts: 18