<?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: transpose select rows to columns? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-report-transpose-select-rows-to-columns/m-p/540912#M149272</link>
    <description>&lt;P&gt;The basic ideas for report is to ensure that each value you want to appear in a column has the appropriate value in a column indicating variable. RETAIN is one way to keep a value across records that are related to use as such. Similar is to have the correct row value. In this case I used literal text as that is fairly clear. Then the values get displayed in the intersections.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc tabulate is similar but the body requires requesting a statistic and suppressing the label to get similar output.&lt;/P&gt;
&lt;P&gt;Tabulate may have advantages if making multiple tables from a single data set as you can have multiple TABLE statements as long as variables maintain the same role: Class (categorical and row or column heading) or Var numeric for summarizations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The two procedures are intended for slightly different purposes with Report being more on the account ledger appearance and allowing calculations referencing other cells and tabulate, IMHO, better when nesting categories in multiple layers both row and column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Mar 2019 20:05:18 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-03-06T20:05:18Z</dc:date>
    <item>
      <title>Proc report: transpose select rows to columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-report-transpose-select-rows-to-columns/m-p/540837#M149242</link>
      <description>&lt;DIV id="messagebodydisplay_0_12" class="lia-message-body lia-component-body"&gt;
&lt;DIV class="lia-message-body-content"&gt;
&lt;P&gt;Hi folks and &lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884" target="_blank" rel="noopener"&gt;@ballardw&lt;/A&gt; ,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to convert DATA HAVE to a DESIRED OUTPUT as shown in the image below.&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="PROC REPORT DESIRED.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/27712iF8485EA9DFBEB472/image-size/large?v=v2&amp;amp;px=999" role="button" title="PROC REPORT DESIRED.png" alt="PROC REPORT DESIRED.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The problem was solved for slightly different data in the post following:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Select-certain-rows-to-transpose-for-a-column/m-p/539495#M148660" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/Select-certain-rows-to-transpose-for-a-column/m-p/539495#M148660&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is the new data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HAVE; LENGTH PARAMETER $10.;
INPUT PARAMETER $ SITES $ Level1 RR LCL UCL;
CARDS;
PM25 LIVER . 1.02 1.01 1.02
SMOKE_CAT LIVER 2 0.86 0.79 0.93
SMOKE_CAT LIVER 3 1.21 1.08 1.34
SMOKE_CAT LIVER 4 1.32 1.10 1.54
SMOKE_CAT LIVER 5 1.25 1.07 1.43
NO2 LIVER . 1.41 1.14 1.68
SMOKE_CAT LIVER 2 0.81 0.63 0.99
SMOKE_CAT LIVER 3 1.60 1.23 1.97
SMOKE_CAT LIVER 4 0.59 0.63 0.54
SMOKE_CAT LIVER 5 0.98 0.96 0.99
PM25 STOMACH . 1.88 1.35 2.40
SMOKE_CAT STOMACH 2 0.34 0.23 0.45
SMOKE_CAT STOMACH 3 2.06 1.44 2.68
SMOKE_CAT STOMACH 4 0.98 0.96 0.99
SMOKE_CAT STOMACH 5 2.25 1.53 2.97
NO2 STOMACH . 2.34 1.57 3.11
SMOKE_CAT STOMACH 2 2.43 1.61 3.25
SMOKE_CAT STOMACH 3 0.58 0.56 0.59
SMOKE_CAT STOMACH 4 2.62 1.70 3.54
SMOKE_CAT STOMACH 5 2.71 1.74 3.68
;
PROC PRINT; RUN; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 06 Mar 2019 18:57:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-report-transpose-select-rows-to-columns/m-p/540837#M149242</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2019-03-06T18:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: Proc report: transpose select rows to columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-report-transpose-select-rows-to-columns/m-p/540848#M149247</link>
      <description>&lt;P&gt;I'm not quite sure what you want for output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 17:45:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-report-transpose-select-rows-to-columns/m-p/540848#M149247</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-06T17:45:55Z</dc:date>
    </item>
    <item>
      <title>Re: Proc report: transpose select rows to columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-report-transpose-select-rows-to-columns/m-p/540851#M149249</link>
      <description>Thanks. Exact same as before. The difference is smoke_cat with 4-levels instead NY with one level in previous example. I can post screenshot using Excel in 10 min.</description>
      <pubDate>Wed, 06 Mar 2019 18:00:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-report-transpose-select-rows-to-columns/m-p/540851#M149249</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2019-03-06T18:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: Proc report: transpose select rows to columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-report-transpose-select-rows-to-columns/m-p/540870#M149255</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; ,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The image shows desired output. I can make painting cells based on the statistical significance a separate post.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PROC REPORT OUTPUT.png" style="width: 444px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/27711iB551821BC419087B/image-size/large?v=v2&amp;amp;px=999" role="button" title="PROC REPORT OUTPUT.png" alt="PROC REPORT OUTPUT.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 18:44:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-report-transpose-select-rows-to-columns/m-p/540870#M149255</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2019-03-06T18:44:18Z</dc:date>
    </item>
    <item>
      <title>Re: Proc report: transpose select rows to columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-report-transpose-select-rows-to-columns/m-p/540881#M149258</link>
      <description>&lt;P&gt;Basically the same approach: make the col and row variables needed conditionally and retain the column values for grouping the columns.&lt;/P&gt;
&lt;PRE&gt;DATA HAVE; 
   LENGTH PARAMETER $10.;
   INPUT PARAMETER $ SITES $ Level1 RR LCL UCL;
   length col $ 5 row $ 20;
   retain col ;
   If parameter in ('PM25' 'NO2') then col=parameter;
   if level1=. then row='Adjusted RR';
   else row= catx(' ','Smoking Level',level1);
CARDS;
PM25 LIVER . 1.02 1.01 1.02
SMOKE_CAT LIVER 2 0.86 0.79 0.93
SMOKE_CAT LIVER 3 1.21 1.08 1.34
SMOKE_CAT LIVER 4 1.32 1.10 1.54
SMOKE_CAT LIVER 5 1.25 1.07 1.43
NO2 LIVER . 1.41 1.14 1.68
SMOKE_CAT LIVER 2 0.81 0.63 0.99
SMOKE_CAT LIVER 3 1.60 1.23 1.97
SMOKE_CAT LIVER 4 0.59 0.63 0.54
SMOKE_CAT LIVER 5 0.98 0.96 0.99
PM25 STOMACH . 1.88 1.35 2.40
SMOKE_CAT STOMACH 2 0.34 0.23 0.45
SMOKE_CAT STOMACH 3 2.06 1.44 2.68
SMOKE_CAT STOMACH 4 0.98 0.96 0.99
SMOKE_CAT STOMACH 5 2.25 1.53 2.97
NO2 STOMACH . 2.34 1.57 3.11
SMOKE_CAT STOMACH 2 2.43 1.61 3.25
SMOKE_CAT STOMACH 3 0.58 0.56 0.59
SMOKE_CAT STOMACH 4 2.62 1.70 3.54
SMOKE_CAT STOMACH 5 2.71 1.74 3.68
;
run;

proc report data=have;
   column sites row col,(rr lcl ucl);
   define sites  /group;
   define row /group;
   define col /across order=data "";
run;
   &lt;/PRE&gt;
&lt;P&gt;The order=data for COL is to preserve the order from the input data set, otherwise the output defaults to formatted (alphabetical) and the "" suppresses the col value name appearing as an overall label.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 18:59:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-report-transpose-select-rows-to-columns/m-p/540881#M149258</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-06T18:59:13Z</dc:date>
    </item>
    <item>
      <title>Re: Proc report: transpose select rows to columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-report-transpose-select-rows-to-columns/m-p/540885#M149260</link>
      <description>&lt;P&gt;WOW. This is not a minor change from the previous programming to me. Glad I asked for your help! Thanks a lot. I will post the question as to paint the cells to red vs green based on the statistical significance. Can I post your solution provided here and tag you on that post following?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 19:07:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-report-transpose-select-rows-to-columns/m-p/540885#M149260</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2019-03-06T19:07:28Z</dc:date>
    </item>
    <item>
      <title>Re: Proc report: transpose select rows to columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-report-transpose-select-rows-to-columns/m-p/540912#M149272</link>
      <description>&lt;P&gt;The basic ideas for report is to ensure that each value you want to appear in a column has the appropriate value in a column indicating variable. RETAIN is one way to keep a value across records that are related to use as such. Similar is to have the correct row value. In this case I used literal text as that is fairly clear. Then the values get displayed in the intersections.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc tabulate is similar but the body requires requesting a statistic and suppressing the label to get similar output.&lt;/P&gt;
&lt;P&gt;Tabulate may have advantages if making multiple tables from a single data set as you can have multiple TABLE statements as long as variables maintain the same role: Class (categorical and row or column heading) or Var numeric for summarizations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The two procedures are intended for slightly different purposes with Report being more on the account ledger appearance and allowing calculations referencing other cells and tabulate, IMHO, better when nesting categories in multiple layers both row and column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 20:05:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-report-transpose-select-rows-to-columns/m-p/540912#M149272</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-06T20:05:18Z</dc:date>
    </item>
  </channel>
</rss>

