<?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 report a table with grouped variables? in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-report-a-table-with-grouped-variables/m-p/433170#M20302</link>
    <description>&lt;P&gt;Thank you for your help. I&amp;nbsp;have&amp;nbsp;tried your method, but the report has some problems.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="snipaste_3.png" style="width: 358px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18254iFA8EA85B76641079/image-size/large?v=v2&amp;amp;px=999" role="button" title="snipaste_3.png" alt="snipaste_3.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Feb 2018 16:40:26 GMT</pubDate>
    <dc:creator>guibuzi</dc:creator>
    <dc:date>2018-02-01T16:40:26Z</dc:date>
    <item>
      <title>How to report a table with grouped variables?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-report-a-table-with-grouped-variables/m-p/433043#M20298</link>
      <description>&lt;P&gt;I encountered some problems when generating a report table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want&amp;nbsp;generating a table in such form (left). But I can only get the form on the right.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="snipaste_1.png" style="width: 373px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18249i5E5F42D221BD82CD/image-size/large?v=v2&amp;amp;px=999" role="button" title="snipaste_1.png" alt="snipaste_1.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="snipaste_2.png" style="width: 325px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18250iA4D469EB58098963/image-size/large?v=v2&amp;amp;px=999" role="button" title="snipaste_2.png" alt="snipaste_2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are my codes:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tmp;
  input num var $ value group count f $ p $;
cards;
1 LMRN 0 1 0 NA NA 
1 LMRN 0 2 0 NA NA 
1 LMRN 1 1 72 NA NA 
1 LMRN 1 2 72 NA NA 
2 LMLN 0 1 0 - 1.0000 
2 LMLN 0 2 1 - 1.0000 
2 LMLN 1 1 72 - 1.0000 
2 LMLN 1 2 71 - 1.0000 
3 YYRN 0 1 1 0.6220 0.6220 
3 YYRN 0 2 3 0.6220 0.6220 
3 YYRN 1 1 70 0.6220 0.6220 
3 YYRN 1 2 69 0.6220 0.6220 
4 YYLN 0 1 2 1.0000 1.0000 
4 YYLN 0 2 2 1.0000 1.0000 
4 YYLN 1 1 69 1.0000 1.0000 
4 YYLN 1 2 70 1.0000 1.0000 
5 YZRN 0 1 61 0.4601 0.4601 
5 YZRN 0 2 64 0.4601 0.4601 
5 YZRN 1 1 11 0.4601 0.4601 
5 YZRN 1 2 8 0.4601 0.4601 
6 YZLN 0 1 58 1.0000 1.0000 
6 YZLN 0 2 58 1.0000 1.0000 
6 YZLN 1 1 14 1.0000 1.0000 
6 YZLN 1 2 14 1.0000 1.0000 
7 HMRN 0 1 0 NA NA 
7 HMRN 0 2 0 NA NA 
7 HMRN 1 1 72 NA NA 
7 HMRN 1 2 72 NA NA 
8 HMLN 0 1 0 NA NA 
8 HMLN 0 2 0 NA NA 
8 HMLN 1 1 72 NA NA 
8 HMLN 1 2 72 NA NA 
;
run;

proc format;
  value group_label 1="Group1"
                    2="Group2";
  value value_label 0="N"
                    1="F";
run;

proc report data=tmp split="|" spanrows style(column)={just=center};
  column var value (count,group f p n);
  define var/group order=data;
  define value/group descending format=value_label.;
  define group/across order=internal format=group_label. '';
  define count/"";
  define n/noprint;
  define f/group 'F' style(column)={vjust=m};
  define p/group 'P value' style(column)={vjust=m};
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 09:01:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-report-a-table-with-grouped-variables/m-p/433043#M20298</guid>
      <dc:creator>guibuzi</dc:creator>
      <dc:date>2018-02-01T09:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to report a table with grouped variables?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-report-a-table-with-grouped-variables/m-p/433103#M20299</link>
      <description>&lt;P&gt;Use ORDER usage not GROUP. and you maybe need to change your data structure.&lt;/P&gt;&lt;P&gt;&lt;BR data-mce-bogus="1" /&gt;&lt;/P&gt;&lt;P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=tmp split="|" nowd spanrows style(column)={just=center};
  column var value count,group  n f p;
  define var/order order=data;
  define value/order descending format=value_label.;
  define group/across order=internal format=group_label. '';
  define count/"";
  define n/noprint;
  define f/order 'F' style(column)={vjust=m};
  define p/order 'P value' style(column)={vjust=m};
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR data-mce-bogus="1" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 13:55:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-report-a-table-with-grouped-variables/m-p/433103#M20299</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-02-01T13:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to report a table with grouped variables?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-report-a-table-with-grouped-variables/m-p/433156#M20300</link>
      <description>&lt;P&gt;Please describe the actual concern? Is it that the cells of like values are not merged?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also show your code (at least). Example data might help.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 16:10:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-report-a-table-with-grouped-variables/m-p/433156#M20300</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-02-01T16:10:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to report a table with grouped variables?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-report-a-table-with-grouped-variables/m-p/433168#M20301</link>
      <description>&lt;P&gt;I'm sorry for my English.&amp;nbsp; 'var'，'value' are grouped variables.&amp;nbsp; I want to&amp;nbsp;generate&amp;nbsp;a report similar to the picture on the left, but I don't want&amp;nbsp;repeat the value of the&amp;nbsp;variable (such as 'f' 'p') from one row to the next if the value does not change.&lt;/P&gt;&lt;P&gt;Example data and my code&amp;nbsp;already posted.&lt;/P&gt;&lt;DIV class="xis-refProc"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 01 Feb 2018 16:36:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-report-a-table-with-grouped-variables/m-p/433168#M20301</guid>
      <dc:creator>guibuzi</dc:creator>
      <dc:date>2018-02-01T16:36:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to report a table with grouped variables?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-report-a-table-with-grouped-variables/m-p/433170#M20302</link>
      <description>&lt;P&gt;Thank you for your help. I&amp;nbsp;have&amp;nbsp;tried your method, but the report has some problems.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="snipaste_3.png" style="width: 358px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18254iFA8EA85B76641079/image-size/large?v=v2&amp;amp;px=999" role="button" title="snipaste_3.png" alt="snipaste_3.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 16:40:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-report-a-table-with-grouped-variables/m-p/433170#M20302</guid>
      <dc:creator>guibuzi</dc:creator>
      <dc:date>2018-02-01T16:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to report a table with grouped variables?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-report-a-table-with-grouped-variables/m-p/433353#M20303</link>
      <description>&lt;P&gt;HI:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; PROC REPORT has limitations and one of the limitations you have discovered. Since the combination of VAR and VALUE produces 2 distinct rows, it is hard to get what you want with the rows in the middle collapsed and the rows on the left and right side of the table to be spanning when you use ACROSS for the GROUP column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; However, you can achieve this type of report with two passes through the data. The first pass is the PROC REPORT step you have to get ALMOST what you want into a DATA set.You can use OUT= to get the dataset you ALMOST want. Here's the PROC REPORT output from the first pass thru the data:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="after_first_pass.png" style="width: 403px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18266i3AC89D1AD023D56D/image-size/large?v=v2&amp;amp;px=999" role="button" title="after_first_pass.png" alt="after_first_pass.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; This first step will collapse the rows and essentially transpose GROUP 1 and GROUP 2. This dataset, WORK.ALMOST will look like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="work_almost.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18267iDF523D5F83A23304/image-size/large?v=v2&amp;amp;px=999" role="button" title="work_almost.png" alt="work_almost.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Then, you can send the WORK.ALMOST data set to PROC REPORT, where the the COLUMN statement will be slightly different and there is no ACROSS usage on the report. Also, I used the NUM variable on both reports to control the order of the VAR column, producing this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="report_2a.png" style="width: 519px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18268i6090405042D6F951/image-size/large?v=v2&amp;amp;px=999" role="button" title="report_2a.png" alt="report_2a.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Here's the complete code (uses the same data that was posted previously):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc format;
  value group_label 1="Group1"
                    2="Group2";
  value value_label 0="N"
                    1="F";
run;
  
** use REPORT to "transpose" data into desired structure;
** include NUM in report for ordering purposes;
** not sure why N is even needed;
proc report data=tmp split="|" spanrows 
     out=work.almost(rename=(_c4_=Group1 _c5_=Group2) drop=_break_)
     style(column)={just=center};
title '1) Original report is ALMOST what is wanted';
title2 'Need to restructure data for RWI';
  column num var value  count,group  f p;
  define num / group noprint;
  define var/group order=data;
  define value/group descending format=value_label.;
  define group/across order=internal format=group_label. '';
  define count/" ";
  define f/group 'F' style(column)={vjust=m};
  define p/group 'P value' style(column)={vjust=m};
run;
  
proc print data=work.almost;
  title 'data set after first pass -- used proc report to transpose and collapse rows';
format value value_label.;
run;
  
proc sort data=work.almost; by num var value;
run;

proc report data=almost spanrows;
  title '2a) Using Transposed and Summarized data with PROC REPORT';
  column num var value group1 group2 f p;
  define num / order noprint;
  define var / order 'Var';
  define value / display 'Value' f=value_label.;
  define group1 / display 'Group 1';
  define group2 / display 'Group 2';
  define f / order 'F';
  define p / order 'P Value';
run;
    &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There's also a solution using the Report Writing Interface, but it would require more logic to control and test for true duplicates in the F and P columns (which is something that the PROC REPORT ORDER usage will do for you automatically).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cynthia&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2018 02:19:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-report-a-table-with-grouped-variables/m-p/433353#M20303</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2018-02-02T02:19:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to report a table with grouped variables?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-report-a-table-with-grouped-variables/m-p/433358#M20304</link>
      <description>Thanks for your help.</description>
      <pubDate>Fri, 02 Feb 2018 02:47:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-report-a-table-with-grouped-variables/m-p/433358#M20304</guid>
      <dc:creator>guibuzi</dc:creator>
      <dc:date>2018-02-02T02:47:09Z</dc:date>
    </item>
  </channel>
</rss>

