<?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 modify the table structure in proc tabulate in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-modify-the-table-structure-in-proc-tabulate/m-p/705380#M216374</link>
    <description>&lt;P&gt;Your desired table does not make any sense.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you wanted the values to appear based on the difference in the two date variables?&amp;nbsp; So the headers would be 0,1,...4 instead?&lt;/P&gt;
&lt;P&gt;If so then just calculate that new variable and use it instead.&lt;/P&gt;</description>
    <pubDate>Fri, 11 Dec 2020 19:54:55 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-12-11T19:54:55Z</dc:date>
    <item>
      <title>How to modify the table structure in proc tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-modify-the-table-structure-in-proc-tabulate/m-p/705358#M216360</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;I am trynig to create this table using proc tabulate as folowing :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data=outputs.base_sin_102020_v1 (where= (type_sinistre in ('CRP') 
and annee_survenance BETWEEN 2016 AND 2020 and annee_ouverture BETWEEN 2016 AND 2020))
format=10.;
class Annee_Survenance annee_ouverture;
var mnt_rc_bis ;
table Annee_Survenance, annee_ouverture*mnt_rc_bis='REG_DEFENSE' * (sum='') ;
title 'Triangle des règlements de la RC ';
title2 '2020 ';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So, I get this table shape (Table 1) :&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-center" image-alt="tabulate_output.PNG" style="width: 572px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/52526i39A241BE42D3A7B5/image-size/large?v=v2&amp;amp;px=999" role="button" title="tabulate_output.PNG" alt="tabulate_output.PNG" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What can I do to get the shape in Table 2&amp;nbsp; without manual editing with excel by translating each row to the right ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="tabulate_2.PNG" style="width: 643px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/52527iE50263C1425CB156/image-size/large?v=v2&amp;amp;px=999" role="button" title="tabulate_2.PNG" alt="tabulate_2.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 18:22:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-modify-the-table-structure-in-proc-tabulate/m-p/705358#M216360</guid>
      <dc:creator>KarimaTouati</dc:creator>
      <dc:date>2020-12-11T18:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to modify the table structure in proc tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-modify-the-table-structure-in-proc-tabulate/m-p/705363#M216361</link>
      <description>&lt;P&gt;A few options (likely not all) jump to mind:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Modify your input data structure so that the code generates the desired output. May need some pre-wrangling/mapping and then stick with PROC TABULATE&lt;/LI&gt;
&lt;LI&gt;Manually calculate the values (SQL, data step, proc means/summary) and then display it with PROC REPORT&lt;/LI&gt;
&lt;LI&gt;Define a VB macro to shift the data&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Those are in order of preference as well. Either way, to try and assist it would be easier if you could provide a fully worked example, in this case use some sample data to replicate your data. Totally fine to make fake data in Excel if you'd like.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: please post data as text at minimum, preferably as a data step. Otherwise to work with your data we'd have to type it out from the picture.&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/271744"&gt;@KarimaTouati&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;BR /&gt;I am trynig to create this table using proc tabulate as folowing :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data=outputs.base_sin_102020_v1 (where= (type_sinistre in ('CRP') 
and annee_survenance BETWEEN 2016 AND 2020 and annee_ouverture BETWEEN 2016 AND 2020))
format=10.;
class Annee_Survenance annee_ouverture;
var mnt_rc_bis ;
table Annee_Survenance, annee_ouverture*mnt_rc_bis='REG_DEFENSE' * (sum='') ;
title 'Triangle des règlements de la RC ';
title2 '2020 ';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So, I get this table shape (Table 1) :&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-center" image-alt="tabulate_output.PNG" style="width: 572px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/52526i39A241BE42D3A7B5/image-size/large?v=v2&amp;amp;px=999" role="button" title="tabulate_output.PNG" alt="tabulate_output.PNG" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What can I do to get the shape in Table 2&amp;nbsp; without manual editing with excel by translating each row to the right ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="tabulate_2.PNG" style="width: 643px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/52527iE50263C1425CB156/image-size/large?v=v2&amp;amp;px=999" role="button" title="tabulate_2.PNG" alt="tabulate_2.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 18:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-modify-the-table-structure-in-proc-tabulate/m-p/705363#M216361</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-12-11T18:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to modify the table structure in proc tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-modify-the-table-structure-in-proc-tabulate/m-p/705380#M216374</link>
      <description>&lt;P&gt;Your desired table does not make any sense.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you wanted the values to appear based on the difference in the two date variables?&amp;nbsp; So the headers would be 0,1,...4 instead?&lt;/P&gt;
&lt;P&gt;If so then just calculate that new variable and use it instead.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 19:54:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-modify-the-table-structure-in-proc-tabulate/m-p/705380#M216374</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-11T19:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to modify the table structure in proc tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-modify-the-table-structure-in-proc-tabulate/m-p/705382#M216376</link>
      <description>&lt;P&gt;Make a second dataset from the first.&amp;nbsp; Adjust annee_ouverture&amp;nbsp; by subtracting&amp;nbsp; (annee_survenance-2016).&amp;nbsp; Then rerun the proc tabulate:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input annee_survenance annee_ouverture mnt_rc_bis;
datalines;
2016 2016  253484 
2016 2017  112726
2016 2018   70632
2016 2019  209216
2016 2020  113369
2017 2017 1267531
2017 2018  382740
2017 2019  450855
2017 2020  343416
2018 2018 4884853
2018 2019 2425972
2018 2020  554144
2019 2019 12074027
2019 2020  3489196
2020 2020  3106294
run;

proc tabulate data=have format=10.;
  class Annee_Survenance annee_ouverture;
  var mnt_rc_bis ;
  table Annee_Survenance, annee_ouverture*mnt_rc_bis='REG_DEFENSE' * (sum='') ;
  title 'Triangle des règlements de la RC ';
  title2 '2020 ';
run;


data vneed / view=vneed;
  set have;
  annee_ouverture =  annee_ouverture - (annee_survenance-2016);
run;


proc tabulate data=vneed format=10.;
  class Annee_Survenance annee_ouverture;
  var mnt_rc_bis ;
  table Annee_Survenance, annee_ouverture*mnt_rc_bis='REG_DEFENSE' * (sum='') ;
  title 'Triangle des règlements de la RC ';
  title2 '2020 ';
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 20:16:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-modify-the-table-structure-in-proc-tabulate/m-p/705382#M216376</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-12-11T20:16:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to modify the table structure in proc tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-modify-the-table-structure-in-proc-tabulate/m-p/705450#M216421</link>
      <description>&lt;P&gt;The row and column header values in a tabulate can be seen as coordinates, that is an intersection resulting in a cell that contains a single value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The leftward shift of the cell values you want means there has been a change in what the class variables represent.&lt;/P&gt;
&lt;P&gt;The layout of Table 2 requires the columns be based on a interval instead of year.&amp;nbsp; You will need to compute that interval, and not label the columns as years,because that would be misleading, but label the columns as an interval.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't know French, so I made up my own sample data.&lt;/P&gt;
&lt;P&gt;Suppose the data is recording the cost of cleanup for various sites cited for violations of environmental regulations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
  do site_id = 1 to 1000;
    citation_year = rand('integer', 2016, 2020);
    cleanup_cost = rand('integer', 500, 1000);
    do cleanup_year = citation_year to 2020;
      cleanup_cost = rand('integer', 1, cleanup_cost);   * simulate costs as always reducing as clean up proceeds;
      output;
    end;
  end;
run;

ods html file='cost.html' style=plateau;

proc tabulate data=have format=dollar12.;
  title "Table version 1";
  class citation_year cleanup_year;
  var cleanup_cost;

  table
   citation_year,cleanup_year * cleanup_cost * sum=''
  ;
run;

data have2;
  set have;
  years_since_citation = cleanup_year - citation_year;  * compute the interval that will be tabulated in version 2;
run;

proc tabulate data=have2 format=dollar12.;
  Title "Table version 2, with tricks";
  class citation_year years_since_citation;
  var cleanup_cost;

  table
   citation_year = ' '   /* trick: blank label causes empty row to never render */
   , 
   years_since_citation 
   * cleanup_cost * sum=''
   /
   box = {               /* trick: put label in box cell instead */
     label='Citation Year'
     style=[verticalalign=bottom]
   } 
  ;
run;

ods html close;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RichardADeVenezia_0-1607785552372.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/52538iBF2E13259B4695BB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RichardADeVenezia_0-1607785552372.png" alt="RichardADeVenezia_0-1607785552372.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Dec 2020 15:08:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-modify-the-table-structure-in-proc-tabulate/m-p/705450#M216421</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-12-12T15:08:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to modify the table structure in proc tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-modify-the-table-structure-in-proc-tabulate/m-p/705961#M216638</link>
      <description>&lt;P&gt;Thank you all for your responses.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Dec 2020 09:05:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-modify-the-table-structure-in-proc-tabulate/m-p/705961#M216638</guid>
      <dc:creator>KarimaTouati</dc:creator>
      <dc:date>2020-12-15T09:05:05Z</dc:date>
    </item>
  </channel>
</rss>

