<?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: Creating a multiway table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-multiway-table/m-p/733287#M228510</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input year_2000 year_2001 year_2002 area gender;
cards;
1 1 1 6 1
1 1 1 8 1
1 1 0 8 2
0 1 1 6 1
1 1 1 8 1
;
run;

proc sql;
create table want as
select 'Area' as a length=40,put(area,best. -l) as b length=40,
       sum(year_2000) as year_2000 label='2000',
	   sum(year_2001) as year_2001 label='2001',
	   sum(year_2002) as year_2002 label='2002'
 from have
  group by area
union all
select 'Gender' as a length=40,put(gender,best. -l) as b length=40,
       sum(year_2000) as year_2000 label='2000',
	   sum(year_2001) as year_2001 label='2001',
	   sum(year_2002) as year_2002 label='2002'
 from have
  group by gender
union all
select 'Total','Total',
       sum(year_2000) as year_2000 label='2000',
	   sum(year_2001) as year_2001 label='2001',
	   sum(year_2002) as year_2002 label='2002'
 from have
 ;
 quit;

 proc report data=want nowd spanrows;
 column a b ('Year' year_2000 year_2001 year_2002);
 define a/group 'Characteristics' style={vjust=m};
 define b/display 'Sub Group';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="x.jpg" style="width: 433px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/57473i29E44F1EA5B84754/image-size/large?v=v2&amp;amp;px=999" role="button" title="x.jpg" alt="x.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Apr 2021 12:18:41 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2021-04-13T12:18:41Z</dc:date>
    <item>
      <title>Creating a multiway table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-multiway-table/m-p/733220#M228500</link>
      <description>&lt;P&gt;I have the following data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;data have;
input year_2000 year_2001 year_2002 area gender;
cards;
1 1 1 6 1
1 1 1 8 1
1 1 0 8 2
0 1 1 6 1
1 1 1 8 1
;
run;
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking at creating the following table with sum value of '1' under year_2000 to year_2002, stratified by 'area' and 'gender', separately. In the end the 'total' row is total in each year (by 'area' or 'gender', it will be the same).&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Priyamvada07_0-1618294625861.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/57462i456B6AE3EBA816B6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Priyamvada07_0-1618294625861.png" alt="Priyamvada07_0-1618294625861.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Any guidance on how to go about making this table?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 13 Apr 2021 06:22:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-multiway-table/m-p/733220#M228500</guid>
      <dc:creator>Priyamvada07</dc:creator>
      <dc:date>2021-04-13T06:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a multiway table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-multiway-table/m-p/733226#M228501</link>
      <description>&lt;P&gt;First transpose the data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data transposed;
   set have;
   
   length group $ 10 subgroup 8 year $ 4 value 8;
   
   array years year_:;
   
   do i = 1 to dim(years);
      year = scan(vname(years[i]), 2, '_');
      value = years[i];
      
      group = 'gender';
      subgroup = gender;      
      output;
      
      group = 'area';
      subgroup = area;
      output;
   end;
   
   drop i year_: area gender;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Afterwards proc report could be used, except for the total-row. i thought about using a multilabel format, but wasn't able to create the expected output:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=work.transposed;
   columns group subgroup year, value;
   
   define group / group ;
   define subgroup / group;
   define year / across;
   define value / sum;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Apr 2021 07:05:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-multiway-table/m-p/733226#M228501</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-04-13T07:05:05Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a multiway table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-multiway-table/m-p/733287#M228510</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input year_2000 year_2001 year_2002 area gender;
cards;
1 1 1 6 1
1 1 1 8 1
1 1 0 8 2
0 1 1 6 1
1 1 1 8 1
;
run;

proc sql;
create table want as
select 'Area' as a length=40,put(area,best. -l) as b length=40,
       sum(year_2000) as year_2000 label='2000',
	   sum(year_2001) as year_2001 label='2001',
	   sum(year_2002) as year_2002 label='2002'
 from have
  group by area
union all
select 'Gender' as a length=40,put(gender,best. -l) as b length=40,
       sum(year_2000) as year_2000 label='2000',
	   sum(year_2001) as year_2001 label='2001',
	   sum(year_2002) as year_2002 label='2002'
 from have
  group by gender
union all
select 'Total','Total',
       sum(year_2000) as year_2000 label='2000',
	   sum(year_2001) as year_2001 label='2001',
	   sum(year_2002) as year_2002 label='2002'
 from have
 ;
 quit;

 proc report data=want nowd spanrows;
 column a b ('Year' year_2000 year_2001 year_2002);
 define a/group 'Characteristics' style={vjust=m};
 define b/display 'Sub Group';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="x.jpg" style="width: 433px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/57473i29E44F1EA5B84754/image-size/large?v=v2&amp;amp;px=999" role="button" title="x.jpg" alt="x.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Apr 2021 12:18:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-multiway-table/m-p/733287#M228510</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-04-13T12:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a multiway table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-multiway-table/m-p/734610#M228815</link>
      <description>&lt;P&gt;If you want a similar result without additional processing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data=HAVE;
  class  AREA GENDER;
  var YEAR_2000 YEAR_2001 YEAR_2002 ;
  table AREA GENDER all,(YEAR_2000 YEAR_2001 YEAR_2002)*sum=' ';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ChrisNZ_0-1618528417980.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58091iA48C3C8CCDC28F49/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ChrisNZ_0-1618528417980.png" alt="ChrisNZ_0-1618528417980.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;This data storage layout is really bad though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 23:14:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-multiway-table/m-p/734610#M228815</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-04-15T23:14:53Z</dc:date>
    </item>
  </channel>
</rss>

