BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Raja
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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;

View solution in original post

2 REPLIES 2
art297
Opal | Level 21

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;

Raja
Calcite | Level 5

Thanks.. this will do for me...

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

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