Help using Base SAS procedures

how to subset observations from a group ?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

how to subset observations from a group ?

Hi everyone

here is the data after  grouping my sample data by subject variable to find counts.

proc sql;

select subject,marks,count(*) as count

from marks

group by subject,marks;

quit;

subject      marks       count

maths        70            3

maths        85          10

maths        90            5

physics      55           3

physics      60           7

physics     80           2

English       75           9

English       85           5

i now want to create a table with  only those observations with max(count) from each subject,which should resemble like this

subject     marks    count

maths      85           10

physics    60           7

English    75           9

help me how to write a prog using proc sql to get this desired output (i dont want to use first. last. method from data step)

thanks in advance.


Accepted Solutions
Solution
‎12-12-2014 11:37 PM
Trusted Advisor
Posts: 1,204

Re: how to subset observations from a group ?

proc sql;

select * from marks

group by subject

having count=max(count);

quit;

View solution in original post


All Replies
Solution
‎12-12-2014 11:37 PM
Trusted Advisor
Posts: 1,204

Re: how to subset observations from a group ?

proc sql;

select * from marks

group by subject

having count=max(count);

quit;

Occasional Contributor
Posts: 7

Re: how to subset observations from a group ?

thankyou stat@sas

its working

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 297 views
  • 1 like
  • 2 in conversation