Create new variable called Adjusted GPA that is the GPA reported in the fileminus the average GPA for everyone.
This is what I have so far:
PROC Summary Data=Students;
Var GPA;
Output out=Students1(Keep=AveGPA) mean=AveGPA;
Run;
Data studentnew;
if_n_=1 then set Students;
set students1;
AdjGPA=(sum"GPA"n)/AveGPA;
AdjGPA= round(AdjGPA, .01);
run;
Your description and code don't match. In one you say GPA-avgGPA, but in the other you divide the two.
Regardless, I think the following will work (although you might have to change the calculation if you are looking for the remainder):
PROC Summary Data=sashelp.class (rename=(age=gpa)); Var gpa; Output out=Students1(Keep=AveGPA) mean=AveGPA; Run; Data studentnew; set sashelp.class (rename=(age=gpa)); if _n_=1 then set students1; AdjGPA=round(GPA/AveGPA, .01); run;
HTH,
Art, CEO, AnalystFinder.com
1. Calculate average and store in dataset
2. Merge with main dataset
3. Subtract
SQL solution, one step.
proc sql;
create table want as
select *,
mean(gpa) as avg_gpa, /*1*/
gpa - calculated avg_gpa as GPA_Residual /*3*/
from students; /*2*/
quit;
Data step/proc solution. Note the datasets names are reversed from yours, and I set Validvarname = V7 so no need for name literals.
options validvarname=v7;
/*1*/
PROC Summary Data=Students;
Var GPA;
Output out=Students1(Keep=AveGPA) mean=AveGPA;
Run;
Data studentnew;
/*2*/
if_n_=1 then set Students1;
set students;
AdjGPA =round( GPA-AveGPA, 0.01); /*3*/
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.