## Want super simple tally on a category

Solved
Regular Contributor
Posts: 238

# Want super simple tally on a category

.

Let's say we have a list of pet types mentioned on a survey:

cat

dog

cat

horse

dog

cat

rabbit

dog

cat

cat

lizard

horse

cat

I simply want a tally of these entries. How many cats, how many dogs, etc.

What would be the most appropriate SAS Proc to accomplish this? Please provide a complete example code.

Thanks,

Nicholas Kormanik

.

Accepted Solutions
Solution
‎11-19-2012 06:52 PM
PROC Star
Posts: 8,167

## Re: Want super simple tally on a category

I'm not sure what you are asking.

Proc freq data=have;

table pets;

run;

or, for all 15 variables:

Proc freq data=have;

tables _all_;

run;

???

All Replies
Regular Contributor
Posts: 151

## Re: Want super simple tally on a category

PROC FREQ is the simplest way of doing this.  Just search for it on the web and you will find many examples you can use, depending on how you want your output (report or data set).

Regular Contributor
Posts: 238

## Re: Want super simple tally on a category

Thanks,

Nicholas

Regular Contributor
Posts: 238

## Re: Want super simple tally on a category

How about Proc SQL?

Thanks,

Nicholas

Super User
Posts: 23,776

## Re: Want super simple tally on a category

There are hundreds of paper on this, search lexjansen.com

What are you actually after?

Here's one from 1993...b/c that's at least how old the question is.

http://www.lexjansen.com/nesug/nesug93/NESUG93010.pdf

Regular Contributor
Posts: 238

## Re: Want super simple tally on a category

The actual case I'm dealing with has around 5,000,000 observations.  And the data file has 15 variables.  So, computationally, some muscle is needed.

What I'm surprised at is that the simple problem above doesn't have a more straight-forward solution in SAS.

In Minitab, another statistics program I like, the answer is found with the command:

tally pets

That's it.  So easy.  Presto.

Unfortunately, however, Minitab chokes on such a large data set.

Solution
‎11-19-2012 06:52 PM
PROC Star
Posts: 8,167

## Re: Want super simple tally on a category

I'm not sure what you are asking.

Proc freq data=have;

table pets;

run;

or, for all 15 variables:

Proc freq data=have;

tables _all_;

run;

???

Regular Contributor
Posts: 238

## Re: Want super simple tally on a category

Excellent assistance from you all.

And very good spot-on papers suggested.

Thanks very much!

Nicholas

Regular Contributor
Posts: 238

## Re: Want super simple tally on a category

For completeness, does anyone know the PROC SQL code to do the same thing?

Thanks

Super Contributor
Posts: 644

## Re: Want super simple tally on a category

Can't check the code but try

Proc SQL ;

create table want as

select distinct pet

,    count(pet) as count

from have

;

Quit ;

Richard in Oz

Posts: 5,541

## Re: Want super simple tally on a category

proc sql;

create table want as

select pet, count(*) as n

from have

group by pet;

quit;

PG

PG
Regular Contributor
Posts: 238

## Re: Want super simple tally on a category

Hmmm.  So in this particular case the PROC FREQ is considerably shorter / more efficient than PROC SQL.

In other instances it's said that more can be done with less code by using SQL.

PROC Star
Posts: 8,167

## Re: Want super simple tally on a category

I think the comparisons typically only compare sql with data step processing and SQL doesn't always win there either.

Regular Contributor
Posts: 238

## Re: Want super simple tally on a category

But is there general gratefulness among many here that SAS does offer the PROC SQL?

Once in a while does it come in super handy?

PROC Star
Posts: 8,167