BookmarkSubscribeRSS Feed
iressa131
Calcite | Level 5

 Hello I am trying  to calculate average class grade after having calculated the grade for each individual student. How would I capture the proc means output and create a new variable from this? I saw a similar question and have played around with the code but its not giving me a new variable. the dataset newP5 includes the individual grades. Thanks for any help!

 

proc means data=newP5;
var Grade;
output out=new mean(Grade)=class;
run;
4 REPLIES 4
novinosrin
Tourmaline | Level 20

Not sure if i understand your question, are you after?

 

proc means data=newP5;
var Grade;
output out=new mean=mean_grade;
run;
iressa131
Calcite | Level 5

Hi this code gives me the same output i have been getting which does give me the correct average but I am looking to create a new variable for that value. For example I average 5 test scores (so i have 5 variables) for each student then get the overall average of 90 but now instead of wanting to just see it in my output, I want it to be a new variable as part of my dataset so that i have a total of 6 variables. I hope that clarified it!

ballardw
Super User

@iressa131 wrote:

Hi this code gives me the same output i have been getting which does give me the correct average but I am looking to create a new variable for that value. For example I average 5 test scores (so i have 5 variables) for each student then get the overall average of 90 but now instead of wanting to just see it in my output, I want it to be a new variable as part of my dataset so that i have a total of 6 variables. I hope that clarified it!


Multiple variables is poor data structure. Better is to have something like
StudentId  TestId Score

 

Then a report procedure:

Proc tabulate data=have;
   class studentid testid;
   var score;
   table studentid,
         (testid all)*score*mean=''
   ;
run;

would create on row per student and have the scores across with the overall mean as the last column.

 

added bonus: use table studentid All,  and you would have the average score for each test across all of the students as the last row.

Astounding
PROC Star

If I understand you correctly, the data set NEWP5 contains the variable CLASS as well as the variable GRADE, holding the grade for each individual student.  In that case:

 

proc summary data=newp5 nway;

class class;

var grade;

output out=want (keep=class class_grade) mean(grade) = class_grade;

run;

 

Take a look at the results by printing the data set WANT.  If it contains the right information, we can talk about how to combine it with the existing data set NEWP5 ... only if you want them combined.

 

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
  • 4 replies
  • 2338 views
  • 0 likes
  • 4 in conversation