turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Studio
- /
- need some help with average calculations

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-05-2017 01:37 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-05-2017 02:41 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-05-2017 02:54 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-05-2017 03:13 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-05-2017 06:11 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-05-2017 06:17 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-05-2017 06:31 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-05-2017 06:39 PM - edited 02-05-2017 06:42 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-05-2017 08:27 PM - edited 02-05-2017 08:27 PM

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.