<?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: freq and sum and average per category in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/freq-and-sum-and-average-per-category/m-p/460943#M117193</link>
    <description>&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=proc&amp;amp;docsetTarget=p0aq3hsvflztfzn1xa2wt6s35oy6.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=de" target="_blank"&gt;proc summary&lt;/A&gt;&amp;nbsp;is all you need.&lt;/P&gt;</description>
    <pubDate>Wed, 09 May 2018 10:29:03 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-05-09T10:29:03Z</dc:date>
    <item>
      <title>freq and sum and average per category</title>
      <link>https://communities.sas.com/t5/SAS-Programming/freq-and-sum-and-average-per-category/m-p/460941#M117192</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I want to ask please how to create the desired output with one proc statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;SPAN&gt;Required Output:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Cat&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;Freq &amp;nbsp; &amp;nbsp; &amp;nbsp;Sum_Wellness &amp;nbsp; &amp;nbsp; &amp;nbsp;Avg_Wellness&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;A &amp;nbsp; &amp;nbsp; &amp;nbsp; 7 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;440 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;62.8&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;B &amp;nbsp; &amp;nbsp; &amp;nbsp; 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;110 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;36.6&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;All &amp;nbsp; &amp;nbsp; 10 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;550 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 55.0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Raw data :&lt;/P&gt;&lt;P&gt;Data aaa;&lt;BR /&gt;Input lakID Cat $ Wellness;&lt;BR /&gt;Cards;&lt;BR /&gt;1 A 10&lt;BR /&gt;2 A 30&lt;BR /&gt;3 B 20&lt;BR /&gt;4 A 60&lt;BR /&gt;5 B 70&lt;BR /&gt;6 B 20&lt;BR /&gt;7 A 50&lt;BR /&gt;8 A 100&lt;BR /&gt;9 A 40&lt;BR /&gt;10 A 150&lt;BR /&gt;;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 09 May 2018 10:25:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/freq-and-sum-and-average-per-category/m-p/460941#M117192</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-05-09T10:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: freq and sum and average per category</title>
      <link>https://communities.sas.com/t5/SAS-Programming/freq-and-sum-and-average-per-category/m-p/460943#M117193</link>
      <description>&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=proc&amp;amp;docsetTarget=p0aq3hsvflztfzn1xa2wt6s35oy6.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=de" target="_blank"&gt;proc summary&lt;/A&gt;&amp;nbsp;is all you need.&lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 10:29:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/freq-and-sum-and-average-per-category/m-p/460943#M117193</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-05-09T10:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: freq and sum and average per category</title>
      <link>https://communities.sas.com/t5/SAS-Programming/freq-and-sum-and-average-per-category/m-p/460945#M117194</link>
      <description>&lt;P&gt;Use proc summary and set output sum=sum_wellness and mean=avg_wellness &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;//Fredrik&lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 10:32:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/freq-and-sum-and-average-per-category/m-p/460945#M117194</guid>
      <dc:creator>FredrikE</dc:creator>
      <dc:date>2018-05-09T10:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: freq and sum and average per category</title>
      <link>https://communities.sas.com/t5/SAS-Programming/freq-and-sum-and-average-per-category/m-p/460964#M117199</link>
      <description>&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;2 problems:&lt;/P&gt;&lt;P&gt;1- I want to define format&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Format &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;_FREQ_ &amp;nbsp;COMMA12. &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;sum_wellness Comma12.1 avg_wellness Comma12.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2-In total raw I want to add "Total" syntax&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data aaa;&lt;BR /&gt;Input lakID Cat $ Wellness;&lt;BR /&gt;Cards;&lt;BR /&gt;1 A 10&lt;BR /&gt;2 A 30&lt;BR /&gt;3 B 20&lt;BR /&gt;4 A 60&lt;BR /&gt;5 B 70&lt;BR /&gt;6 B 20&lt;BR /&gt;7 A 50&lt;BR /&gt;8 A 100&lt;BR /&gt;9 A 40&lt;BR /&gt;10 A 150&lt;BR /&gt;;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc summary data=aaa ;&lt;BR /&gt;class Cat;&lt;BR /&gt;var Wellness;&lt;BR /&gt;output out=pelet(rename=(_FREQ_=Lak)) sum=sum_wellness mean=avg_wellness;&lt;BR /&gt;Format &amp;nbsp;&lt;SPAN&gt;_FREQ_ &amp;nbsp;COMMA12. &amp;nbsp;&lt;/SPAN&gt;sum_wellness Comma12.1 avg_wellness Comma12.;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 11:51:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/freq-and-sum-and-average-per-category/m-p/460964#M117199</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-05-09T11:51:25Z</dc:date>
    </item>
    <item>
      <title>Re: freq and sum and average per category</title>
      <link>https://communities.sas.com/t5/SAS-Programming/freq-and-sum-and-average-per-category/m-p/460968#M117200</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;2 problems:&lt;/P&gt;
&lt;P&gt;1- I want to define format&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Format &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;_FREQ_ &amp;nbsp;COMMA12. &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;sum_wellness Comma12.1 avg_wellness Comma12.;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2-In total raw I want to add "Total" syntax&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;1 — Assign the formats when you use data set PELET after PROC SUMMARY&lt;/P&gt;
&lt;P&gt;2 — I don't understand this at all, what do you mean?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 12:06:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/freq-and-sum-and-average-per-category/m-p/460968#M117200</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-05-09T12:06:41Z</dc:date>
    </item>
    <item>
      <title>Re: freq and sum and average per category</title>
      <link>https://communities.sas.com/t5/SAS-Programming/freq-and-sum-and-average-per-category/m-p/460971#M117201</link>
      <description>&lt;P&gt;I know to do it in 2 step&lt;/P&gt;&lt;P&gt;My question is how to do it in one step only?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data aaa;&lt;BR /&gt;Input lakID Cat $ Wellness ;&lt;BR /&gt;Cards;&lt;BR /&gt;1 A 10&lt;BR /&gt;2 A 30&lt;BR /&gt;3 B 20&lt;BR /&gt;4 A 60&lt;BR /&gt;5 B 70&lt;BR /&gt;6 B 2000&lt;BR /&gt;7 A 50&lt;BR /&gt;8 A 100&lt;BR /&gt;9 A 40&lt;BR /&gt;10 A 1500&lt;BR /&gt;;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;/*Step1*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;proc summary data=aaa ;&lt;BR /&gt;class Cat;&lt;BR /&gt;var Wellness;&lt;BR /&gt;output out=pelet(rename=(_FREQ_=Lak)) sum=sum_wellness mean=avg_wellness;&lt;BR /&gt;/*Format sum_wellness Comma12.1 avg_wellness Comma12.;*/&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Step2*/&lt;BR /&gt;Data pelet2;&lt;BR /&gt;Set pelet;&lt;BR /&gt;IF cat='' then cat='Total';&lt;BR /&gt;Format sum_wellness avg_wellness Comma12.;&lt;BR /&gt;Run;&lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 12:15:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/freq-and-sum-and-average-per-category/m-p/460971#M117201</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-05-09T12:15:34Z</dc:date>
    </item>
    <item>
      <title>Re: freq and sum and average per category</title>
      <link>https://communities.sas.com/t5/SAS-Programming/freq-and-sum-and-average-per-category/m-p/460976#M117202</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I know to do it in 2 step&lt;/P&gt;
&lt;P&gt;My question is how to do it in one step only?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't think you can do it in one step.&lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 12:27:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/freq-and-sum-and-average-per-category/m-p/460976#M117202</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-05-09T12:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: freq and sum and average per category</title>
      <link>https://communities.sas.com/t5/SAS-Programming/freq-and-sum-and-average-per-category/m-p/461060#M117231</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data aaa;
Input lakID Cat $ Wellness;
Cards;
1 A 10
2 A 30
3 B 20
4 A 60
5 B 70
6 B 20
7 A 50
8 A 100
9 A 40
10 A 150
;
Run;


data _null_;
if _n_=1 then do;
 dcl hash H () ;
   h.definekey  ("cat") ;
   h.definedata ("cat","freq","Sum_Wellness", "Avg_Wellness") ;
   h.definedone () ;
    declare hiter iter('h');
 end;
set aaa end=last;
call missing(Avg_Wellness);
if h.check() ne 0 then do;
freq=1;
Sum_Wellness=sum(Sum_Wellness,Wellness);
Avg_Wellness=Sum_Wellness/freq;
h.replace();
end;
else do;
h.find();
freq=freq+1;
Sum_Wellness=sum(Sum_Wellness,Wellness);
Avg_Wellness=Sum_Wellness/freq;
h.replace();
end;
_freq+1;
if last then do;
rc = iter.first();
do while (rc = 0);
_Sum_Wellness+Sum_Wellness;
  rc = iter.next();
end;
cat='all';
freq=_freq;
Sum_Wellness=_Sum_Wellness;
Avg_Wellness=divide(Sum_Wellness,freq);
h.add();
h.output(dataset:'want');
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 May 2018 14:56:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/freq-and-sum-and-average-per-category/m-p/461060#M117231</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-09T14:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: freq and sum and average per category</title>
      <link>https://communities.sas.com/t5/SAS-Programming/freq-and-sum-and-average-per-category/m-p/461087#M117243</link>
      <description>&lt;P&gt;Perhaps you do really just want a report?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=work.aaa;
 class cat;
 var wellness;
 table cat all='Total',
       wellness*(n='Freq'*f=comma12. sum*f=comma12.1 mean='Average'*f=comma12.)
       /
 ;
run;&lt;/PRE&gt;
&lt;P&gt;Note that if you have multiple variables that want a similar summary you would 1) add them to the VAR statement and the tables such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=work.aaa;
 class cat;
 var wellness niceness otherness;
 table cat all='Total',
       (wellness niceness otherness)*(n='Freq'*f=comma12. sum*f=comma12.1 mean='Average'*f=comma12.)
       /
 ;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 May 2018 15:36:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/freq-and-sum-and-average-per-category/m-p/461087#M117243</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-09T15:36:09Z</dc:date>
    </item>
  </channel>
</rss>

