<?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: How to produce min, max and average using Accumulating Variables ? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-produce-min-max-and-average-using-Accumulating-Variables/m-p/610324#M76763</link>
    <description>&lt;P&gt;You're on the right track, but you're not doing it for the right groups, if the instructions say:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;find the minimum, maximum and average GPA separately&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for &lt;STRONG&gt;each combination of gender, school and grade&lt;/STRONG&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;And remember, although you cannot use PROC MEANS for&amp;nbsp;your final answer you can use it to check your results. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This portion outputs each for each studentNum.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if last.STUDENT_NUM;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;You're not doing student level analysis, so you don't need to consider it in&amp;nbsp;your analysis&amp;nbsp;because it identifies unique students. You've left it in as&amp;nbsp;your primary grouper though so that's incorrect.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/295349"&gt;@K_Wils15&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Have a final next week and I am not sure how to answer this question:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assume you have a SAS data set called 'GPA_DATA' that contains the variables STUDENT_NUM SCHOOL GRADE&lt;BR /&gt;GENDER and GPA. Write all of the SAS code necessary to find the minimum, maximum and average GPA separately&lt;BR /&gt;for each combination of gender, school and grade.&lt;BR /&gt;You must use accumulating variables to accomplish all of this (NOT Proc Means).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the code I have so far (I added notes to help me stay oriented). Am I on the right track? Do I need to add anything else? :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data GPA_Data2;&lt;BR /&gt;set GPA_DATA;&lt;BR /&gt;where STUDENT_NUM ne . and Gender ne '' and Grade ne . and SCHOOL ne '' and GPA ne .;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=GPA_DATA2 out=GPA_DATA3;&lt;BR /&gt;by STUDENT_NUM SCHOOL GRADE GENDER GPA;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data NEW_GPA_DATA (keep = STUDENT_NUM SCHOOL GRADE GENDER n_gpa min_gpa max_gpa avg_gpa sum_gpa);&lt;BR /&gt;set GPA_DATA3;&lt;BR /&gt;by STUDENT_NUM SCHOOL GRADE GENDER GPA;&lt;BR /&gt;retain min_gpa max_gpa sum_gpa n_gpa;&lt;BR /&gt;if first.STUDENT_NUM then do;&lt;BR /&gt;min_gpa = GPA;&lt;BR /&gt;* Since we sorted in ascending order the first record will have the min GPA.;&lt;BR /&gt;max_gpa = GPA; * After this we will look for larger GPAs.;&lt;BR /&gt;sum_GPA = 0;&lt;BR /&gt;n_GPA = 0;&lt;BR /&gt;end;&lt;BR /&gt;sum_gpa = sum(sum_gpa, GPA);&lt;BR /&gt;n_gpa = sum(n_gpa, 1);&lt;BR /&gt;max_gpa = max(max_gpa, GPA);&lt;BR /&gt;avg_gpa = sum_gpa / n_gpa;&lt;BR /&gt;* Do not have to worry about divide by zero since we added 1 three lines up.;&lt;BR /&gt;if last.STUDENT_NUM;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc print data=NEW_GPA_DATA;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 08 Dec 2019 19:38:37 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-12-08T19:38:37Z</dc:date>
    <item>
      <title>How to produce min, max and average using Accumulating Variables ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-produce-min-max-and-average-using-Accumulating-Variables/m-p/610299#M76760</link>
      <description>&lt;P&gt;Have a final next week and I am not sure how to answer this question:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Assume you have a SAS data set called 'GPA_DATA' that contains the variables STUDENT_NUM SCHOOL GRADE&lt;BR /&gt;GENDER and GPA. Write all of the SAS code necessary to find the minimum, maximum and average GPA separately&lt;BR /&gt;for each combination of gender, school and grade.&lt;BR /&gt;You must use accumulating variables to accomplish all of this (NOT Proc Means).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code I have so far (I added notes to help me stay oriented). Am I on the right track? Do I need to add anything else? :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data GPA_Data2;&lt;BR /&gt;set GPA_DATA;&lt;BR /&gt;where STUDENT_NUM ne . and Gender ne '' and Grade ne . and SCHOOL ne '' and GPA ne .;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=GPA_DATA2 out=GPA_DATA3;&lt;BR /&gt;by STUDENT_NUM SCHOOL GRADE GENDER GPA;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data NEW_GPA_DATA (keep = STUDENT_NUM SCHOOL GRADE GENDER n_gpa min_gpa max_gpa avg_gpa sum_gpa);&lt;BR /&gt;set GPA_DATA3;&lt;BR /&gt;by STUDENT_NUM SCHOOL GRADE GENDER GPA;&lt;BR /&gt;retain min_gpa max_gpa sum_gpa n_gpa;&lt;BR /&gt;if first.STUDENT_NUM then do;&lt;BR /&gt;min_gpa = GPA;&lt;BR /&gt;* Since we sorted in ascending order the first record will have the min GPA.;&lt;BR /&gt;max_gpa = GPA; * After this we will look for larger GPAs.;&lt;BR /&gt;sum_GPA = 0;&lt;BR /&gt;n_GPA = 0;&lt;BR /&gt;end;&lt;BR /&gt;sum_gpa = sum(sum_gpa, GPA);&lt;BR /&gt;n_gpa = sum(n_gpa, 1);&lt;BR /&gt;max_gpa = max(max_gpa, GPA);&lt;BR /&gt;avg_gpa = sum_gpa / n_gpa;&lt;BR /&gt;* Do not have to worry about divide by zero since we added 1 three lines up.;&lt;BR /&gt;if last.STUDENT_NUM;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc print data=NEW_GPA_DATA;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Dec 2019 17:11:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-produce-min-max-and-average-using-Accumulating-Variables/m-p/610299#M76760</guid>
      <dc:creator>K_Wils15</dc:creator>
      <dc:date>2019-12-08T17:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to produce min, max and average using Accumulating Variables ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-produce-min-max-and-average-using-Accumulating-Variables/m-p/610324#M76763</link>
      <description>&lt;P&gt;You're on the right track, but you're not doing it for the right groups, if the instructions say:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;find the minimum, maximum and average GPA separately&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for &lt;STRONG&gt;each combination of gender, school and grade&lt;/STRONG&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;And remember, although you cannot use PROC MEANS for&amp;nbsp;your final answer you can use it to check your results. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This portion outputs each for each studentNum.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if last.STUDENT_NUM;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;You're not doing student level analysis, so you don't need to consider it in&amp;nbsp;your analysis&amp;nbsp;because it identifies unique students. You've left it in as&amp;nbsp;your primary grouper though so that's incorrect.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/295349"&gt;@K_Wils15&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Have a final next week and I am not sure how to answer this question:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assume you have a SAS data set called 'GPA_DATA' that contains the variables STUDENT_NUM SCHOOL GRADE&lt;BR /&gt;GENDER and GPA. Write all of the SAS code necessary to find the minimum, maximum and average GPA separately&lt;BR /&gt;for each combination of gender, school and grade.&lt;BR /&gt;You must use accumulating variables to accomplish all of this (NOT Proc Means).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the code I have so far (I added notes to help me stay oriented). Am I on the right track? Do I need to add anything else? :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data GPA_Data2;&lt;BR /&gt;set GPA_DATA;&lt;BR /&gt;where STUDENT_NUM ne . and Gender ne '' and Grade ne . and SCHOOL ne '' and GPA ne .;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=GPA_DATA2 out=GPA_DATA3;&lt;BR /&gt;by STUDENT_NUM SCHOOL GRADE GENDER GPA;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data NEW_GPA_DATA (keep = STUDENT_NUM SCHOOL GRADE GENDER n_gpa min_gpa max_gpa avg_gpa sum_gpa);&lt;BR /&gt;set GPA_DATA3;&lt;BR /&gt;by STUDENT_NUM SCHOOL GRADE GENDER GPA;&lt;BR /&gt;retain min_gpa max_gpa sum_gpa n_gpa;&lt;BR /&gt;if first.STUDENT_NUM then do;&lt;BR /&gt;min_gpa = GPA;&lt;BR /&gt;* Since we sorted in ascending order the first record will have the min GPA.;&lt;BR /&gt;max_gpa = GPA; * After this we will look for larger GPAs.;&lt;BR /&gt;sum_GPA = 0;&lt;BR /&gt;n_GPA = 0;&lt;BR /&gt;end;&lt;BR /&gt;sum_gpa = sum(sum_gpa, GPA);&lt;BR /&gt;n_gpa = sum(n_gpa, 1);&lt;BR /&gt;max_gpa = max(max_gpa, GPA);&lt;BR /&gt;avg_gpa = sum_gpa / n_gpa;&lt;BR /&gt;* Do not have to worry about divide by zero since we added 1 three lines up.;&lt;BR /&gt;if last.STUDENT_NUM;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc print data=NEW_GPA_DATA;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Dec 2019 19:38:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-produce-min-max-and-average-using-Accumulating-Variables/m-p/610324#M76763</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-12-08T19:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to produce min, max and average using Accumulating Variables ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-produce-min-max-and-average-using-Accumulating-Variables/m-p/610327#M76764</link>
      <description>Thank you!</description>
      <pubDate>Sun, 08 Dec 2019 19:52:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-produce-min-max-and-average-using-Accumulating-Variables/m-p/610327#M76764</guid>
      <dc:creator>K_Wils15</dc:creator>
      <dc:date>2019-12-08T19:52:12Z</dc:date>
    </item>
  </channel>
</rss>

