turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- Analytics
- /
- Stat Procs
- /
- computing median by class

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-04-2011 12:16 PM

Hi !

I have this following requirement:

I have a data file 'Score' with two columns.

The first column name is 'School' and second column name is 'marks'.

I have four schools named 'A', 'B', 'C', 'D'. School A has marks for 40 students, school B has that for 30 students, school C for 32 students and school D has that for 10 students.

So in total I have 112 rows in the data set

I want to write a SAS code which first computes the median marks for each school and then removes data for all students which is below the median score for that particular school.

Can you help me to code this?

Thanks

Raja

Accepted Solutions

Solution

08-04-2011
12:36 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-04-2011 12:36 PM

How about something like:

data have;

input school marks;

cards;

1 1

1 2

1 3

1 4

1 5

2 1

2 2

2 3

2 4

;

proc summary data=have nway;

var marks;

class school;

output out=medians (drop=_ median=median;

run;

data want;

merge have medians;

by school;

if marks ge median;

run;

All Replies

Solution

08-04-2011
12:36 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-04-2011 12:36 PM

How about something like:

data have;

input school marks;

cards;

1 1

1 2

1 3

1 4

1 5

2 1

2 2

2 3

2 4

;

proc summary data=have nway;

var marks;

class school;

output out=medians (drop=_ median=median;

run;

data want;

merge have medians;

by school;

if marks ge median;

run;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-04-2011 12:40 PM

Thanks.. this will do for me...