<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Help on calculations in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Help-on-calculations/m-p/331664#M1866</link>
    <description>&lt;P&gt;1. Calculate average and store in dataset&lt;/P&gt;
&lt;P&gt;2. Merge with main dataset&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Subtract&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SQL solution, one step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as 
select *, &lt;BR /&gt;mean(gpa) as avg_gpa,  /*1*/&lt;BR /&gt;gpa - calculated avg_gpa as GPA_Residual /*3*/
from students; /*2*/
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Data step/proc solution. Note the datasets names are reversed from yours, and I set Validvarname = V7 so no need for name literals.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 10 Feb 2017 20:20:13 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-02-10T20:20:13Z</dc:date>
    <item>
      <title>Help on calculations</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Help-on-calculations/m-p/331649#M1864</link>
      <description>&lt;P&gt;Create new variable called Adjusted GPA that is the GPA reported in the fileminus the average GPA for everyone.&lt;/P&gt;&lt;P&gt;This is what I have so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC Summary Data=Students;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Var GPA;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Output out=Students1(Keep=AveGPA) mean=AveGPA;&lt;BR /&gt;Run;&lt;BR /&gt;Data studentnew;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if_n_=1 then set Students;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;set students1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;AdjGPA=(sum"GPA"n)/AveGPA;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;AdjGPA= round(AdjGPA, .01);&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 19:42:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Help-on-calculations/m-p/331649#M1864</guid>
      <dc:creator>jeaster0</dc:creator>
      <dc:date>2017-02-10T19:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: Help on calculations</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Help-on-calculations/m-p/331655#M1865</link>
      <description>&lt;P&gt;Your description and code don't match. In one you say GPA-avgGPA, but in the other you divide the two.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regardless, I think the following will work (although you might have to change the calculation if you are looking for the remainder):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;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;
&lt;/PRE&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 19:59:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Help-on-calculations/m-p/331655#M1865</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-10T19:59:15Z</dc:date>
    </item>
    <item>
      <title>Re: Help on calculations</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Help-on-calculations/m-p/331664#M1866</link>
      <description>&lt;P&gt;1. Calculate average and store in dataset&lt;/P&gt;
&lt;P&gt;2. Merge with main dataset&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Subtract&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SQL solution, one step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as 
select *, &lt;BR /&gt;mean(gpa) as avg_gpa,  /*1*/&lt;BR /&gt;gpa - calculated avg_gpa as GPA_Residual /*3*/
from students; /*2*/
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Data step/proc solution. Note the datasets names are reversed from yours, and I set Validvarname = V7 so no need for name literals.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 20:20:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Help-on-calculations/m-p/331664#M1866</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-10T20:20:13Z</dc:date>
    </item>
  </channel>
</rss>

