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

I want Section, Std who is having highest Avergare Marks,

 

Please help....

 

also please advice anyweblink/soft copy/ thru which i can improve proc sql.

 

 

thank you so much in advance

 

 

data ds1;
input section $ std $Subject $ Marks;
datalines;
A Ramesh Maths 30
A Ramesh English 40
A Ramesh Hindi 50
A Suresh Maths 60
A Suresh English 70
A Suresh Hindi 80
B Mahesh Maths 30
B Mahesh English 60
B Mahesh Hindi 50
B Kailash Maths 80
B Kailash English 90
B Kailash Hindi 90
;
proc print;
run;

proc sql;
select max(Avg(Marks) from ds1 group by std;
quit;

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data ds1;
input section $ std $Subject $ Marks;
datalines;
A Ramesh Maths 30
A Ramesh English 40
A Ramesh Hindi 50
A Suresh Maths 60
A Suresh English 70
A Suresh Hindi 80
B Mahesh Maths 30
B Mahesh English 60
B Mahesh Hindi 50
B Kailash Maths 80
B Kailash English 90
B Kailash Hindi 90
;
run;
proc sql;
  select  *
  from    (select SECTION,
                  STD,
                  AVG(MARKS) as AVG_MARKS
           from   DS1 
           group by SECTION,
                    STD)
  
  having  AVG_MARKS=max(AVG_MARKS);
quit;

View solution in original post

7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Something like the below?  You haven't shown what the output should look like.

To learn SQL, if that is your other question, there are many resources online, Google them.  W3 schools for instance is a good reference.

 

data ds1;
input section $ std $Subject $ Marks;
datalines;
A Ramesh Maths 30
A Ramesh English 40
A Ramesh Hindi 50
A Suresh Maths 60
A Suresh English 70
A Suresh Hindi 80
B Mahesh Maths 30
B Mahesh English 60
B Mahesh Hindi 50
B Kailash Maths 80
B Kailash English 90
B Kailash Hindi 90
;
run;
proc sql;
  create table WANT as
  select  SECTION,
          STD
  from    (select SECTION,
                  STD,
                  AVG(MARKS) as AVG_MARKS
           from   DS1 
           group by SECTION,
                    STD)
  group by SECTION,
           STD
  having  AVG_MARKS=max(AVG_MARKS);
quit;

 

atul_desh
Quartz | Level 8

I want section, Std in output who is having highest Average marks...

 

I'm not sure but 

 

having  AVG_MARKS=max(AVG_MARKS) is not working

 

Thanks,

Reeza
Super User

What does not working mean?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Per @Reeza, what is not working.  Are there log outputs?  What should the output look like, is it a logic problem?

Rick_SAS
SAS Super FREQ

Do you need to use SQL? PROC MEANS can compute the means for each section and student. Then just sort the data or use SQL on the output statistics:

 

/* compute mean of each student in each section */
proc means data=ds1 noprint;
by section;
class std;
output mean= out=MeanOut(where=(_TYPE_=1) drop=_FREQ_);
run;

/* sort by mean marks */
proc sort data=MeanOut; by Marks; run;

proc print noobs data=MeanOut(obs=1 drop=_TYPE_); run;
atul_desh
Quartz | Level 8

Thanks Rick,

 

but i want if it could done with proc sql;

 

Thanks for your support !!

Ksharp
Super User
data ds1;
input section $ std $Subject $ Marks;
datalines;
A Ramesh Maths 30
A Ramesh English 40
A Ramesh Hindi 50
A Suresh Maths 60
A Suresh English 70
A Suresh Hindi 80
B Mahesh Maths 30
B Mahesh English 60
B Mahesh Hindi 50
B Kailash Maths 80
B Kailash English 90
B Kailash Hindi 90
;
run;
proc sql;
  select  *
  from    (select SECTION,
                  STD,
                  AVG(MARKS) as AVG_MARKS
           from   DS1 
           group by SECTION,
                    STD)
  
  having  AVG_MARKS=max(AVG_MARKS);
quit;

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1375 views
  • 3 likes
  • 5 in conversation