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;
... View more