<?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: Proc Summary in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Summary/m-p/826863#M326609</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input REGION $ CODE $ DATE :datetime20. TRAVEL QTY PRICE;
format date datetime20.;
datalines;
EAST	D1234TN		05MAY2022:07:03:13	14.38	19.12	56.98
EAST	D1234TN		05MAY2022:08:26:45	14.12	19.02	56.68
EAST	D1234TN		06MAY2022:15:11:02	23.31	18.74	72.52
EAST	E2689PV	  	04MAY2022:07:03:15	18.80	19.10	64.37
EAST	E2689PV		.					11.50	19.50	52.84
SOUTH	G1539GV		25MAY2022:08:49:37	39.46	19.70	146.57
SOUTH	G1539GV		19MAY2022:07:02:44	 8.26	 7.25	27.75
SOUTH	G2216NV		10MAY2022:11:07:03	16.59	19.98	90.91
;
run;

proc sql;
create table want as
select 1 as id,REGION ,CODE,count(*) as count,
 sum(TRAVEL) as total_TRAVEL,
 sum(QTY) as total_QTY,
 sum(PRICE) as total_PRICE,

 avg(TRAVEL) as avg_TRAVEL,
 avg(QTY) as avg_QTY,
 avg(PRICE) as avg_PRICE

 from have
  group by REGION ,CODE 

union all
select 2 as id,REGION ,put(count(distinct CODE),best. -l),count(*) as count,
 sum(TRAVEL) as total_TRAVEL,
 sum(QTY) as total_QTY,
 sum(PRICE) as total_PRICE,

 avg(TRAVEL) as avg_TRAVEL,
 avg(QTY) as avg_QTY,
 avg(PRICE) as avg_PRICE

 from have
  group by REGION  

order by 2,1
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 03 Aug 2022 13:33:04 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2022-08-03T13:33:04Z</dc:date>
    <item>
      <title>Proc Summary</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Summary/m-p/826843#M326598</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a detailed data as shown in below code, could someone help me with the summary I am looking for as shown in below output image.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input REGION $ CODE $ DATE :datetime20. TRAVEL QTY PRICE;
format date datetime20.;
datalines;
EAST	D1234TN		05MAY2022:07:03:13	14.38	19.12	56.98
EAST	D1234TN		05MAY2022:08:26:45	14.12	19.02	56.68
EAST	D1234TN		06MAY2022:15:11:02	23.31	18.74	72.52
EAST	E2689PV	  	04MAY2022:07:03:15	18.80	19.10	64.37
EAST	E2689PV		.					11.50	19.50	52.84
SOUTH	G1539GV		25MAY2022:08:49:37	39.46	19.70	146.57
SOUTH	G1539GV		19MAY2022:07:02:44	 8.26	 7.25	27.75
SOUTH	G2216NV		10MAY2022:11:07:03	16.59	19.98	90.91
;
run;&lt;/PRE&gt;
&lt;P&gt;expected output&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vnreddy_0-1659531474335.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/74055iDC85A0E85A34A889/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vnreddy_0-1659531474335.png" alt="vnreddy_0-1659531474335.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;1. I want to derive count from codes for example &lt;STRONG&gt;D1234TN &lt;/STRONG&gt;repeated 3 times in source so the count will be 3&lt;/P&gt;
&lt;P&gt;2. I want to have have total_travel, total_qty, total_price&amp;nbsp;from travel,qty,price columns&lt;/P&gt;
&lt;P&gt;3. Avg_travel should be derived from total_travel/count against each code as shown in above image&lt;/P&gt;
&lt;P&gt;4. Avg_qty and avg_price from total_qty/count and total_price/count&lt;/P&gt;
&lt;P&gt;5. Finally, I want to show bolded row for&amp;nbsp;total count of codes on a region wise, and total count, sum(total_travel), sum(total_qty), sum(total_price) and average(travel),average(qty),average(price)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; regards,&lt;/P&gt;
&lt;P&gt;vnreddy.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2022 12:58:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Summary/m-p/826843#M326598</guid>
      <dc:creator>vnreddy</dc:creator>
      <dc:date>2022-08-03T12:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Summary</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Summary/m-p/826846#M326600</link>
      <description>&lt;P&gt;Can you show us your desired result given this data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Makes it much easier to provide a usable code answer &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2022 12:57:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Summary/m-p/826846#M326600</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-08-03T12:57:14Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Summary</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Summary/m-p/826849#M326602</link>
      <description>Hi, &lt;BR /&gt;&lt;BR /&gt;posted the expected output image</description>
      <pubDate>Wed, 03 Aug 2022 12:59:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Summary/m-p/826849#M326602</guid>
      <dc:creator>vnreddy</dc:creator>
      <dc:date>2022-08-03T12:59:38Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Summary</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Summary/m-p/826860#M326607</link>
      <description>&lt;P&gt;PROC SUMMARY cannot make text bold. You can do that in PROC REPORT. It also will not place a 2 in the CODE column, or order the results the way you want. You can use PROC SORT to get the proper ordering and a DATA step to place a 2 in the code column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have;
    class region code;
    types region region*code;
    var travel qty price;
    output out=want mean= sum=/autoname;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2022 13:20:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Summary/m-p/826860#M326607</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-08-03T13:20:55Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Summary</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Summary/m-p/826863#M326609</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input REGION $ CODE $ DATE :datetime20. TRAVEL QTY PRICE;
format date datetime20.;
datalines;
EAST	D1234TN		05MAY2022:07:03:13	14.38	19.12	56.98
EAST	D1234TN		05MAY2022:08:26:45	14.12	19.02	56.68
EAST	D1234TN		06MAY2022:15:11:02	23.31	18.74	72.52
EAST	E2689PV	  	04MAY2022:07:03:15	18.80	19.10	64.37
EAST	E2689PV		.					11.50	19.50	52.84
SOUTH	G1539GV		25MAY2022:08:49:37	39.46	19.70	146.57
SOUTH	G1539GV		19MAY2022:07:02:44	 8.26	 7.25	27.75
SOUTH	G2216NV		10MAY2022:11:07:03	16.59	19.98	90.91
;
run;

proc sql;
create table want as
select 1 as id,REGION ,CODE,count(*) as count,
 sum(TRAVEL) as total_TRAVEL,
 sum(QTY) as total_QTY,
 sum(PRICE) as total_PRICE,

 avg(TRAVEL) as avg_TRAVEL,
 avg(QTY) as avg_QTY,
 avg(PRICE) as avg_PRICE

 from have
  group by REGION ,CODE 

union all
select 2 as id,REGION ,put(count(distinct CODE),best. -l),count(*) as count,
 sum(TRAVEL) as total_TRAVEL,
 sum(QTY) as total_QTY,
 sum(PRICE) as total_PRICE,

 avg(TRAVEL) as avg_TRAVEL,
 avg(QTY) as avg_QTY,
 avg(PRICE) as avg_PRICE

 from have
  group by REGION  

order by 2,1
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Aug 2022 13:33:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Summary/m-p/826863#M326609</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-08-03T13:33:04Z</dc:date>
    </item>
  </channel>
</rss>

