02-10-2017 02:42 PM
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;
Output out=Students1(Keep=AveGPA) mean=AveGPA;
if_n_=1 then set Students;
AdjGPA= round(AdjGPA, .01);
02-10-2017 02:59 PM
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;
Art, CEO, AnalystFinder.com
02-10-2017 03:20 PM
1. Calculate average and store in dataset
2. Merge with main dataset
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;