DATA Step, Macro, Functions and more

Count function

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

Count function

I have a dataset with thousands of datalines that I need counted.  Here's an example of what I'm trying to do:

 

dataset exampe1:

 

erica
ericb
erica
ericb
erica
sarab
sarac
sarab

 

 

I would like to take dataset example1 and create this output:

 

 # of times
a
# of times
b
# of times
c
eric320
sara021

 

 

 

Thank you!


Accepted Solutions
Solution
‎04-12-2017 01:23 AM
Contributor
Posts: 57

Re: Count function

proc sql;
create table want as
select name,grade, count(*) as total from one group by name,grade;
quit;
proc transpose data=want out=result(drop=_NAME_) prefix=total_;
by name;
id grade;
var total;
run;

View solution in original post


All Replies
Solution
‎04-12-2017 01:23 AM
Contributor
Posts: 57

Re: Count function

proc sql;
create table want as
select name,grade, count(*) as total from one group by name,grade;
quit;
proc transpose data=want out=result(drop=_NAME_) prefix=total_;
by name;
id grade;
var total;
run;
Occasional Contributor
Posts: 13

Re: Count function

Posted in reply to lakshmi_74

Thanks so much!  You're awesome!

Super User
Posts: 11,343

Re: Count function

proc tabulate data=have;

    class name grade;

    table name, grade*n='';

run;

 

If you want a report and do not need a dataset.

Occasional Contributor
Posts: 13

Re: Count function

Thank you

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 195 views
  • 2 likes
  • 3 in conversation