BookmarkSubscribeRSS Feed
mp50
Calcite | Level 5

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

8 REPLIES 8
Astounding
PROC Star

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.

LinusH
Tourmaline | Level 20

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
mp50
Calcite | Level 5

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.

Astounding
PROC Star

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.

mp50
Calcite | Level 5

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.

Astounding
PROC Star

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.

mp50
Calcite | Level 5

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

mp50
Calcite | Level 5

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. 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

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
  • 8 replies
  • 1305 views
  • 0 likes
  • 3 in conversation