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
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.
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;
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.
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.
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.
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.
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
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.