Write and run SAS programs in your web browser

Help on calculations

Reply
New Contributor
Posts: 2

Help on calculations

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;

PROC Star
Posts: 7,428

Re: Help on calculations

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

 

Super User
Posts: 19,008

Re: Help on calculations

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;

 

Ask a Question
Discussion stats
  • 2 replies
  • 170 views
  • 0 likes
  • 3 in conversation