<?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 report compute before in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-report-compute-before/m-p/790957#M253278</link>
    <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="a1.png" style="width: 816px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67514iD6D89914D1B3D7A6/image-size/large?v=v2&amp;amp;px=999" role="button" title="a1.png" alt="a1.png" /&gt;&lt;/span&gt;replacing the data set by a joined table to do the aggregation does the job.&lt;/P&gt;
&lt;P&gt;but I can imagine that a compute before should work as well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc cas;
    fedSQL.execDirect / 
        query="create table public.sum22{options replace=true} as 
select a.*, b.fini, put(a.year,4.) as _year 
               from PUBLIC.ALL_MONTHLY_COPY a   join 
(select sum(fin) as fini, from_brand, year from 
PUBLIC.ALL_MONTHLY_COPY where month(mes) &amp;lt;=6 and 
lowcase(producto) &amp;lt;&amp;gt; 'other' AND (VN_VN ='10' or VN_VN = '11') group by from_brand, year 
) b 
on a.from_brand=b.from_brand and a.year=b.year ";
quit;


options missing=0;
proc report data=public.sum22 nowd center split="*" out=three  ;
where lowcase(producto) ne "other" and month('month'n) le 6 AND VN_VN IN ('10' '11');
/* by vn_vn channel; */
format 'month'n monyy. vn_vn $vner.;
column from_brand to_brand  year,  (fini pct_fin ren pct_ren mkpi )  kpi  ;
define year / 'YTD JUN'  center order=internal across;
define pct_ren / 'Share Ren' computed format=percent9.1;
define pct_fin / 'Share Fin' computed format=percent9.1;
define from_brand / group 'from brand' center;
define to_brand / group 'to brand' center ;
define fini / analysis max 'Ven.' ;
define ren / analysis sum  'Ren.'   ;
define kpi / computed f=percent9.1 'delta vs prev. YTD' style(column)={background=ampel.};
define mkpi / computed f=percent9.1 'KPI' style(column)={background=fpcta.};

   rbreak after / summarize;



   /*Add explanatory text to first summary row*/
   compute before from_brand ;
	ren_total2019 = _c5_;
	   ren_total2020 = _c10_;
	   ren_total2021 = _c15_;
	fin_total2019 = _c3_;
	   fin_total2020 = _c8_;
	   fin_total2021 = _c13_;
   endcomp;


compute pct_fin;
_c4_=_c3_/fin_total2019;
_c9_=_c8_/fin_total2020;
_c14_=_c13_/fin_total2021;
endcomp;

compute pct_ren;
_c6_=_c5_/ren_total2019;
_c11_=_c10_/ren_total2020;
_c16_=_c15_/ren_total2021;
endcomp;



compute kpi;
kpi = _c12_ - _c7_;
endcomp;

compute mkpi;
_c7_=_c5_/_c3_;_c12_=_c10_/_c8_;_c17_=_c15_/_c13_;
endcomp;

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Jan 2022 17:06:10 GMT</pubDate>
    <dc:creator>acordes</dc:creator>
    <dc:date>2022-01-19T17:06:10Z</dc:date>
    <item>
      <title>proc report compute before</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-compute-before/m-p/790901#M253252</link>
      <description>&lt;P&gt;I'm struggling to sum the 'Ven.' column as compute before from brand.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, I want &lt;STRONG&gt;&lt;EM&gt;17788&lt;/EM&gt;&lt;/STRONG&gt; to appear in every row of the first block for year 2021 so that the KPI column gets calculated as 'Ren.' (correct) divided by 'Ven.'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for the moment I only share the screenshot while preparing a data set and the code to play with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="a1.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67505iA6CC5A0775AFFDBC/image-size/large?v=v2&amp;amp;px=999" role="button" title="a1.png" alt="a1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=PUBLIC.ALL_MONTHLY_copy nowd center split="*" out=three  ;
where lowcase(producto) ne "other" and month('month'n) le 6 AND VN_VN IN ('10' '11');
/* by vn_vn channel; */
format 'month'n monyy. vn_vn $vner.;
column from_brand to_brand  year,  (fin pct_fin ren pct_ren mkpi )  kpi ;
define year / 'YTD JUN'  center order=internal across;
define pct_ren / 'Share Ren' computed format=percent9.1;
define pct_fin / 'Share Fin' computed format=percent9.1;
define from_brand / group 'from brand' center;
define to_brand / group 'to brand' center ;
define fin / analysis sum 'Ven.' ;
define ren / analysis sum  'Ren.'   ;
define kpi / computed f=percent9.1 'delta vs prev. YTD' style(column)={background=ampel.};
define mkpi / computed f=percent9.1 'KPI' style(column)={background=fpcta.};

   rbreak after / summarize;

   /*Add explanatory text to first summary row*/
   compute before from_brand;
	ren_total2019 = _c5_;
	   ren_total2020 = _c10_;
	   ren_total2021 = _c15_;
	fin_total2019 = _c3_;
	   fin_total2020 = _c8_;
	   fin_total2021 = _c13_;
   endcomp;


compute pct_fin;
_c4_=_c3_/fin_total2019;
_c9_=_c8_/fin_total2020;
_c14_=_c13_/fin_total2021;
endcomp;

compute pct_ren;
_c6_=_c5_/ren_total2019;
_c11_=_c10_/ren_total2020;
_c16_=_c15_/ren_total2021;
endcomp;



compute kpi;
kpi = _c12_ - _c7_;
endcomp;

compute mkpi;
_c7_=_c5_/_c3_;_c12_=_c10_/_c8_;_c17_=_c15_/_c13_;
endcomp;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jan 2022 14:57:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-compute-before/m-p/790901#M253252</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2022-01-19T14:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: proc report compute before</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-compute-before/m-p/790957#M253278</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="a1.png" style="width: 816px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67514iD6D89914D1B3D7A6/image-size/large?v=v2&amp;amp;px=999" role="button" title="a1.png" alt="a1.png" /&gt;&lt;/span&gt;replacing the data set by a joined table to do the aggregation does the job.&lt;/P&gt;
&lt;P&gt;but I can imagine that a compute before should work as well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc cas;
    fedSQL.execDirect / 
        query="create table public.sum22{options replace=true} as 
select a.*, b.fini, put(a.year,4.) as _year 
               from PUBLIC.ALL_MONTHLY_COPY a   join 
(select sum(fin) as fini, from_brand, year from 
PUBLIC.ALL_MONTHLY_COPY where month(mes) &amp;lt;=6 and 
lowcase(producto) &amp;lt;&amp;gt; 'other' AND (VN_VN ='10' or VN_VN = '11') group by from_brand, year 
) b 
on a.from_brand=b.from_brand and a.year=b.year ";
quit;


options missing=0;
proc report data=public.sum22 nowd center split="*" out=three  ;
where lowcase(producto) ne "other" and month('month'n) le 6 AND VN_VN IN ('10' '11');
/* by vn_vn channel; */
format 'month'n monyy. vn_vn $vner.;
column from_brand to_brand  year,  (fini pct_fin ren pct_ren mkpi )  kpi  ;
define year / 'YTD JUN'  center order=internal across;
define pct_ren / 'Share Ren' computed format=percent9.1;
define pct_fin / 'Share Fin' computed format=percent9.1;
define from_brand / group 'from brand' center;
define to_brand / group 'to brand' center ;
define fini / analysis max 'Ven.' ;
define ren / analysis sum  'Ren.'   ;
define kpi / computed f=percent9.1 'delta vs prev. YTD' style(column)={background=ampel.};
define mkpi / computed f=percent9.1 'KPI' style(column)={background=fpcta.};

   rbreak after / summarize;



   /*Add explanatory text to first summary row*/
   compute before from_brand ;
	ren_total2019 = _c5_;
	   ren_total2020 = _c10_;
	   ren_total2021 = _c15_;
	fin_total2019 = _c3_;
	   fin_total2020 = _c8_;
	   fin_total2021 = _c13_;
   endcomp;


compute pct_fin;
_c4_=_c3_/fin_total2019;
_c9_=_c8_/fin_total2020;
_c14_=_c13_/fin_total2021;
endcomp;

compute pct_ren;
_c6_=_c5_/ren_total2019;
_c11_=_c10_/ren_total2020;
_c16_=_c15_/ren_total2021;
endcomp;



compute kpi;
kpi = _c12_ - _c7_;
endcomp;

compute mkpi;
_c7_=_c5_/_c3_;_c12_=_c10_/_c8_;_c17_=_c15_/_c13_;
endcomp;

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jan 2022 17:06:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-compute-before/m-p/790957#M253278</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2022-01-19T17:06:10Z</dc:date>
    </item>
  </channel>
</rss>

