<?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: Create new variable with proc means in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-with-proc-means/m-p/473809#M121622</link>
    <description>&lt;P&gt;If I understand you correctly, the data set NEWP5 contains the variable CLASS as well as the variable GRADE, holding the grade for each individual student.&amp;nbsp; In that case:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc summary data=newp5 nway;&lt;/P&gt;
&lt;P&gt;class class;&lt;/P&gt;
&lt;P&gt;var grade;&lt;/P&gt;
&lt;P&gt;output out=want (keep=class class_grade) mean(grade) = class_grade;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Take a look at the results by printing the data set WANT.&amp;nbsp; If it contains the right information, we can talk about how to combine it with the existing data set NEWP5 ... only if you want them combined.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Jun 2018 16:19:06 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-06-27T16:19:06Z</dc:date>
    <item>
      <title>Create new variable with proc means</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-with-proc-means/m-p/473796#M121617</link>
      <description>&lt;P&gt;&amp;nbsp;Hello I am trying&amp;nbsp; to calculate average class grade after having calculated the grade for each individual student. How would I capture the proc means output and create a new variable from this? I saw a similar question and have played around with the code but its not giving me a new variable. the dataset newP5 includes the individual grades. Thanks for any help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=newP5;
var Grade;
output out=new mean(Grade)=class;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Jun 2018 16:03:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-with-proc-means/m-p/473796#M121617</guid>
      <dc:creator>iressa131</dc:creator>
      <dc:date>2018-06-27T16:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable with proc means</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-with-proc-means/m-p/473798#M121618</link>
      <description>&lt;P&gt;Not sure if i understand your question, are you after?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=newP5;
var Grade;
output out=new mean=mean_grade;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Jun 2018 16:07:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-with-proc-means/m-p/473798#M121618</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-27T16:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable with proc means</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-with-proc-means/m-p/473807#M121621</link>
      <description>&lt;P&gt;Hi this code gives me the same output i have been getting which does give me the correct average but I am looking to create a new variable for that value. For example I average 5 test scores (so i have 5 variables) for each student then get the overall average of 90 but now instead of wanting to just see it in my output, I want it to be a new variable as part of my dataset so that i have a total of 6 variables. I hope that clarified it!&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 16:18:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-with-proc-means/m-p/473807#M121621</guid>
      <dc:creator>iressa131</dc:creator>
      <dc:date>2018-06-27T16:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable with proc means</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-with-proc-means/m-p/473809#M121622</link>
      <description>&lt;P&gt;If I understand you correctly, the data set NEWP5 contains the variable CLASS as well as the variable GRADE, holding the grade for each individual student.&amp;nbsp; In that case:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc summary data=newp5 nway;&lt;/P&gt;
&lt;P&gt;class class;&lt;/P&gt;
&lt;P&gt;var grade;&lt;/P&gt;
&lt;P&gt;output out=want (keep=class class_grade) mean(grade) = class_grade;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Take a look at the results by printing the data set WANT.&amp;nbsp; If it contains the right information, we can talk about how to combine it with the existing data set NEWP5 ... only if you want them combined.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 16:19:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-with-proc-means/m-p/473809#M121622</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-06-27T16:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable with proc means</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-with-proc-means/m-p/473829#M121632</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/192118"&gt;@iressa131&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi this code gives me the same output i have been getting which does give me the correct average but I am looking to create a new variable for that value. For example I average 5 test scores &lt;STRONG&gt;&lt;FONT color="#0000ff"&gt;(so i have 5 variables)&lt;/FONT&gt; &lt;/STRONG&gt;for each student then get the overall average of 90 but now instead of wanting to just see it in my output, I want it to be a new variable as part of my dataset so that i have a total of 6 variables. I hope that clarified it!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Multiple variables is poor data structure. Better is to have something like&lt;BR /&gt;StudentId&amp;nbsp; TestId Score&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then a report procedure:&lt;/P&gt;
&lt;PRE&gt;Proc tabulate data=have;
   class studentid testid;
   var score;
   table studentid,
         (testid all)*score*mean=''
   ;
run;&lt;/PRE&gt;
&lt;P&gt;would create on row per student and have the scores across with the overall mean as the last column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;added bonus: use table studentid All,&amp;nbsp; and you would have the average score for each test across all of the students as the last row.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 17:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-with-proc-means/m-p/473829#M121632</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-06-27T17:11:17Z</dc:date>
    </item>
  </channel>
</rss>

