<?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: Crosstabulation of sums in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Crosstabulation-of-sums/m-p/279127#M16165</link>
    <description>&lt;P&gt;I think this does the job ... see if it matches your expectations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc tabulate data=have;&lt;/P&gt;
&lt;P&gt;class r1-r10 c1-c6;&lt;/P&gt;
&lt;P&gt;var weightvar;&lt;/P&gt;
&lt;P&gt;tables r1-r10, (c1-c6) * weightvar * sum=' ';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Tue, 21 Jun 2016 19:36:29 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-06-21T19:36:29Z</dc:date>
    <item>
      <title>Crosstabulation of sums</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Crosstabulation-of-sums/m-p/279123#M16164</link>
      <description>&lt;P&gt;I have a database of households. C1-C6 represent attributes that a household may or may not have. &amp;nbsp;They are not mutually exclusive. &amp;nbsp;R1-R10 represent a different set of attributes, again not mutually exclusive. &amp;nbsp;This is survey data, and the records have weights W. &amp;nbsp; I want to output a table with C1-C6 on the columns and R1-R10 in the rows, where each cell is the weighted count of households that have that combination of attributes Rx and Cx. &amp;nbsp;I want to avoid having "yes" and "no" columns for each Cx, and similarly for the rows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can recode the data any way I want, and I can use whatever Base SAS procedure(s) (9.3) I like.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a relatively straight-forward way to do this? &amp;nbsp;I feel like there should be, and I'm just not seeing it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;--Dav&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jun 2016 19:19:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Crosstabulation-of-sums/m-p/279123#M16164</guid>
      <dc:creator>Davanden</dc:creator>
      <dc:date>2016-06-21T19:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: Crosstabulation of sums</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Crosstabulation-of-sums/m-p/279127#M16165</link>
      <description>&lt;P&gt;I think this does the job ... see if it matches your expectations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc tabulate data=have;&lt;/P&gt;
&lt;P&gt;class r1-r10 c1-c6;&lt;/P&gt;
&lt;P&gt;var weightvar;&lt;/P&gt;
&lt;P&gt;tables r1-r10, (c1-c6) * weightvar * sum=' ';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jun 2016 19:36:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Crosstabulation-of-sums/m-p/279127#M16165</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-06-21T19:36:29Z</dc:date>
    </item>
    <item>
      <title>Re: Crosstabulation of sums</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Crosstabulation-of-sums/m-p/279334#M16172</link>
      <description>&lt;P&gt;Thank you for your help. &amp;nbsp;That doesn't do what I want. &amp;nbsp;Defining the c and r variables as 0/1 flags, the code produces a table that has columns for 0 and 1 values for each c, and rows for 0 and one for each r (see picture). &amp;nbsp;What I want is the "1" columns and rows without the "0"s.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;--Dav&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3708i5A210B1DBAEBD046/image-size/medium?v=v2&amp;amp;px=-1" border="0" alt="Table 15 output.PNG" title="Table 15 output.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 14:04:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Crosstabulation-of-sums/m-p/279334#M16172</guid>
      <dc:creator>Davanden</dc:creator>
      <dc:date>2016-06-22T14:04:48Z</dc:date>
    </item>
    <item>
      <title>Re: Crosstabulation of sums</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Crosstabulation-of-sums/m-p/279338#M16173</link>
      <description>&lt;P&gt;To some extent you can get around this.&amp;nbsp; But the table isn't necessarily pretty since it doesn't eliminate the "1" labeling.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Modify the PROC TABULATE to create an output data set.&amp;nbsp; Off the top of my head (needs to be verified ... getting very thin up there these days), the code would be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc tabulate data=have noprint;&lt;/P&gt;
&lt;P&gt;class r1-r10 c1-c6;&lt;/P&gt;
&lt;P&gt;var weightvar;&lt;/P&gt;
&lt;P&gt;tables r1-r10, (c1-c6) * weightvar * sum=' ' / out=tabulate_results;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then subset those results before printing with another PROC TABULATE:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set tabulate_results;&lt;/P&gt;
&lt;P&gt;array nums {16} c1-c6 r1-r10;&lt;/P&gt;
&lt;P&gt;do _n_=1 to 16;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if nums{_n_}=0 then delete;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc tabulate data=want;&lt;/P&gt;
&lt;P&gt;class r1-r10 c1-c6;&lt;/P&gt;
&lt;P&gt;var weightvar_sum;&lt;/P&gt;
&lt;P&gt;tables r1-r10, (c1-c6) * weightvar_sum * sum=' ';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output data set automatically creates WEIGHTVAR_SUM, given that you started with an analysis variable WEIGHTVAR and requested the SUM.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you have created the data set WANT, there may be better ways to print your final report.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 14:11:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Crosstabulation-of-sums/m-p/279338#M16173</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-06-22T14:11:34Z</dc:date>
    </item>
    <item>
      <title>Re: Crosstabulation of sums</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Crosstabulation-of-sums/m-p/279536#M16174</link>
      <description>&lt;P&gt;Thank you again for your help. &amp;nbsp;I was hoping to do this in one step, but I see how I can do it in two. &amp;nbsp;The code below shows the basic logic. &amp;nbsp;It will have to be fixed up to put proper labels on the rows and columns, but I know how to do that.&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;P&gt;--Dav&lt;/P&gt;&lt;P&gt;&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=TEST out=Table15 ;
     CLASS  c1-c7 r1-r4;
     VAR  unit;
     
     TABLE
         (r1-r4),
          (c1-c7)*unit=' '*sum=' '*F=Comma7.
     ;     
RUN;

DATA outTable15 (KEEP = row Col1-Col7);
     SET Table15;

     /* keep records corresponding to a 1 in the row and column */
     IF WHICHN(1,OF c1-c7) &amp;gt; 0 AND WhichN(1, of r1-r4)&amp;gt;0;

     /* the dataset is sorted by rows.  populate output column variables */
     RETAIN Col1-Col7;
     ARRAY COL[7] col1-col7;
     Col[whichN(1,of c1-c7)] = Unit_sum;

     /* write the row to the output dataset */
     IF C7=1 THEN DO;
          Row = WhichN(1, of R1-R4); /* row identifier */
          OUTPUT;
     END;
RUN;

PROC PRINT DATA=OutTable15 NOBS;
     VAR ROW Col1-Col7;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;Row    Col1    Col2    Col3    Col4    Col5    Col6    Col7

 1     1124    6436    2069    1080    1738    2245    3963
 2     1111    5503    1213    1080    1917    2195    3629
 3     1050    6063    1916    1019    1776    2112    3670
 4     1185    5876    1366    1141    1879    2328    3922&lt;/PRE&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;</description>
      <pubDate>Wed, 22 Jun 2016 19:24:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Crosstabulation-of-sums/m-p/279536#M16174</guid>
      <dc:creator>Davanden</dc:creator>
      <dc:date>2016-06-22T19:24:59Z</dc:date>
    </item>
  </channel>
</rss>

