BookmarkSubscribeRSS Feed
jeaster0
Calcite | Level 5

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;

2 REPLIES 2
art297
Opal | Level 21

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

 

Reeza
Super User

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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1050 views
  • 0 likes
  • 3 in conversation