<?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 How to stack rows in a report in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-stack-rows-in-a-report/m-p/689564#M209642</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to produce a report where variables have several categories. It looks like this:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Variable&lt;/TD&gt;&lt;TD&gt;Category&lt;/TD&gt;&lt;TD&gt;Value (counts)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Residence&lt;/TD&gt;&lt;TD&gt;Urban&lt;/TD&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Rural&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Education&lt;/TD&gt;&lt;TD&gt;None&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Primary&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Secondary&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Tertuary&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;So I need to stack rows for Residence, Education, etc. For example, for Residence, the Variable column will have one stacked row, while Categories and Values will have two rows (urban and rural). For Education, the Variable column will also have one stacked row, while Categories and Values will have four rows. I know that you can stack columns in PROC TEMPLATE, but I need to stack rows. I can produce a SAS dataset that has this structure, but I wonder if there is a more efficient way to do it - using PROC TEMPLATE or PROC REPORT. Many thanks for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;-Olga&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Oct 2020 15:29:41 GMT</pubDate>
    <dc:creator>Olga3</dc:creator>
    <dc:date>2020-10-07T15:29:41Z</dc:date>
    <item>
      <title>How to stack rows in a report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stack-rows-in-a-report/m-p/689564#M209642</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to produce a report where variables have several categories. It looks like this:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Variable&lt;/TD&gt;&lt;TD&gt;Category&lt;/TD&gt;&lt;TD&gt;Value (counts)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Residence&lt;/TD&gt;&lt;TD&gt;Urban&lt;/TD&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Rural&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Education&lt;/TD&gt;&lt;TD&gt;None&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Primary&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Secondary&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Tertuary&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;So I need to stack rows for Residence, Education, etc. For example, for Residence, the Variable column will have one stacked row, while Categories and Values will have two rows (urban and rural). For Education, the Variable column will also have one stacked row, while Categories and Values will have four rows. I know that you can stack columns in PROC TEMPLATE, but I need to stack rows. I can produce a SAS dataset that has this structure, but I wonder if there is a more efficient way to do it - using PROC TEMPLATE or PROC REPORT. Many thanks for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;-Olga&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 15:29:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stack-rows-in-a-report/m-p/689564#M209642</guid>
      <dc:creator>Olga3</dc:creator>
      <dc:date>2020-10-07T15:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to stack rows in a report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stack-rows-in-a-report/m-p/689581#M209650</link>
      <description>&lt;P&gt;Please look closely at the way that your "example" appears and see if that is what you actually want. I suspect that the forum might have moved somethings from the second column to the first.&lt;/P&gt;
&lt;P&gt;If not, that is a very hard to read layout.&lt;/P&gt;
&lt;P&gt;If the columns were shifted for some values then please show the expected layout. Best would be to provide some actual data and the layout of the expected result using that data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;/&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 15:16:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stack-rows-in-a-report/m-p/689581#M209650</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-07T15:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to stack rows in a report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stack-rows-in-a-report/m-p/689594#M209654</link>
      <description>Thank you ballardw. I corrected my example.</description>
      <pubDate>Wed, 07 Oct 2020 15:30:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stack-rows-in-a-report/m-p/689594#M209654</guid>
      <dc:creator>Olga3</dc:creator>
      <dc:date>2020-10-07T15:30:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to stack rows in a report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stack-rows-in-a-report/m-p/689625#M209665</link>
      <description>&lt;P&gt;Are all of the variables of interest character or do you have a mix of character and numeric? There are some approaches that work with one type of data that don't work with mixed data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one way with only character data which reshapes the data.&lt;/P&gt;
&lt;PRE&gt;data need;
   set sashelp.shoes;
   array v region product;
   /* length for name based on longest name of variables
      value based on longest length of any of the variables
   */
   length name $ 20 value $15;
   do i = 1 to dim(V);
      name = vname(v[i]);
      value = v[i];
      output;
   end;
   keep name value;
run;

proc tabulate data=need;
   class name value;
   table name=''*value='',
         n='Count'
   ;
run;
   &lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Oct 2020 16:50:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stack-rows-in-a-report/m-p/689625#M209665</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-07T16:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to stack rows in a report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stack-rows-in-a-report/m-p/691023#M210274</link>
      <description>&lt;P&gt;Thank you! I already have a code that produces a SAS dataset that is shaped the way I need the output to be. What I asked about was if there is a way to display the results without extra coding. For stacked columns, proc report and proc tabulate have this option. But I haven't found a similar option for rows.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Oct 2020 17:36:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stack-rows-in-a-report/m-p/691023#M210274</guid>
      <dc:creator>Olga3</dc:creator>
      <dc:date>2020-10-12T17:36:23Z</dc:date>
    </item>
  </channel>
</rss>

