Write and run SAS programs in your web browser

need some help with average calculations

Reply
Occasional Contributor
Posts: 8

need some help with average calculations

Hi all,

Need some help with some average. the question that i have is:

Creating new variable eg AdjustedGPA from a dataset that has GPA in the file minus the average GPA for the whole dataset. I tried the mean function by

proc means data=exam.Students;
var GPA;
run;

I also tried sum

DATA students; set students1;
AveGPA = sum(GPA);
run;

it gave the same results for the average and the gpa.

I also need to calculate the adjusted GPA for the whole dataset.

 

so how do i do it. i use sas for acedemics.

 

thank you

Respected Advisor
Posts: 4,648

Re: need some help with average calculations

Try it as two steps:

 

proc summary data=exam.students;

var GPA;

output out=means (keep=AveGPA) mean=AveGPA;

run;

 

data want;

if _n_=1 then set means;

set exam.students;

run;

 

This gets you the average GPA on every observation in EXAM.STUDENTS.

Esteemed Advisor
Posts: 5,091

Re: need some help with average calculations

Perhaps there are other ways, but you could perhaps make use of a neat feature in SAS SQL, remerge statistics with original data. Try something like:

proc sql;
create table want as
select *, GPA - mean(GPA) as AdjustedGPA 
from have;
quit;
Data never sleeps
Occasional Contributor
Posts: 8

Re: need some help with average calculations

hey,

I like your sql suggestion but i need to stick to sas studio as that is what my school wants. however, i tried the previous suggestion and i was able to get an average GPA for the whole dataset. the purpose of the average GPA was to calculate the adjusted GPA. so the adjusted gpa should be the gpa that is reported in the file minus the average gpa. i still havent figured the last part. so please help me.

Respected Advisor
Posts: 4,648

Re: need some help with average calculations

Do you mean you need to know how to add this to the final DATA step:

 

AdjustedGPA = GPA - AveGPA;

 

Also consider an alternative:

 

AdjustedGPA = GPA / AveGPA;

 

It might be easier to work with values that are always positive instead of a mix of positive and negative ... depends on the analysis you are planning.

Occasional Contributor
Posts: 8

Re: need some help with average calculations

I tried this but its giving "." in all GPA, AveGPA and AdjustedGPA.

 

data exam.students;
set exam.students1;
adjustedGPA= AveGPA-GPA;
run;

I need to have all three variables in the dataset students. and i am not sure how to work with values. i am really new at this so i am lost. i do appreciate your help and guidance.

Respected Advisor
Posts: 4,648

Re: need some help with average calculations

This means the original construction of your data set is faulty.  All the GPA values are missing.  You'll have to go back to the step that created the data set in the first place.

Occasional Contributor
Posts: 8

Re: need some help with average calculations

[ Edited ]

Sorry mistake. It was good until i did this step

data exam.students;
set exam.students1;
adjustedGPA= AveGPA-GPA;
run;

after that step, the adjustedgpa and avegpa are showing "."

so where do you think i have gone wrong. as you suggested before it could be the negative values but i am not sure how to calculate the adjusted gpa otherwise. I also tried the GPA/AveGPA and still there are dots. so how do i calculate with values

Occasional Contributor
Posts: 8

Re: need some help with average calculations

[ Edited ]

hey,

I figured the adjusted GPA. it was really traumatic but got it in the end. I thank you and the other poster for your help. 

Post a Question
Discussion Stats
  • 8 replies
  • 108 views
  • 0 likes
  • 3 in conversation