<?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: Transpose 1 column in 3 column table in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Transpose-1-column-in-3-column-table/m-p/58681#M16487</link>
    <description>Hi:&lt;BR /&gt;
  In this instance, you want to count or summarize the customers for each product, but within each product, you want to show the counts for each department. In Proc Report, this kind of summarizing is accomplished by defining a variable or variable as a GROUP variable. Since all you want is the COUNT, you can accomplish this by asking for the N statistic on the column statement:&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc report data=product nowd&lt;BR /&gt;
            split='#';&lt;BR /&gt;
  title 'Proc Report Counts for Product and Department';&lt;BR /&gt;
  column product department n;&lt;BR /&gt;
  define product /group 'Prod';&lt;BR /&gt;
  define department / group 'Dept';&lt;BR /&gt;
  define n / 'Customer#Count';&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Or, you could ask for the explicit count of customers with this version of the code, but for all intents and purposes, the count of all observations( example above) and the count of customers (example below) will get you the same results:&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc report data=product nowd;&lt;BR /&gt;
  title 'Proc Report Cross Customer with Count';&lt;BR /&gt;
  column product department customer,n;&lt;BR /&gt;
  define product /group 'Prod';&lt;BR /&gt;
  define department / group 'Dept';&lt;BR /&gt;
  define n / 'Count';&lt;BR /&gt;
  define customer / 'Customer';&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
    <pubDate>Mon, 03 Nov 2008 18:26:24 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2008-11-03T18:26:24Z</dc:date>
    <item>
      <title>Transpose 1 column in 3 column table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Transpose-1-column-in-3-column-table/m-p/58677#M16483</link>
      <description>Hi guys&lt;BR /&gt;
&lt;BR /&gt;
Please help me to solve a problem, regarding &lt;B&gt;proc transpose&lt;/B&gt;.&lt;BR /&gt;
For example I have a table:&lt;BR /&gt;
-------------------------------------------------------------------&lt;BR /&gt;
| CUSTOMER | DEPARTMENT |  PRODUCT  |&lt;BR /&gt;
-------------------------------------------------------------------&lt;BR /&gt;
|         001      |         300          |       Coffe     |&lt;BR /&gt;
|         002      |         500          |        Tea      |&lt;BR /&gt;
|         002      |         500          |        Tea      |&lt;BR /&gt;
|         002      |         500          |       Coffe     |&lt;BR /&gt;
|         003      |         700          |       Coffe     |&lt;BR /&gt;
|         003      |         700          |        Tea      |&lt;BR /&gt;
&lt;BR /&gt;
And I need to write it to excel file in the following view:&lt;BR /&gt;
-------------------------------------------------------------------&lt;BR /&gt;
| CUSTOMER | DEPARTMENT |  Coffe  | Tea |&lt;BR /&gt;
-------------------------------------------------------------------&lt;BR /&gt;
|        001       |         300          |     1    |   0   |&lt;BR /&gt;
|        002       |         500          |     1    |   2   |&lt;BR /&gt;
|        003       |         700          |     1    |   1   |&lt;BR /&gt;
&lt;BR /&gt;
I tried to use PROC TRANSPOSE here, but cannot understand how does it work.&lt;BR /&gt;
Please help.&lt;BR /&gt;
Thank you.</description>
      <pubDate>Thu, 30 Oct 2008 18:11:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Transpose-1-column-in-3-column-table/m-p/58677#M16483</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-30T18:11:26Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose 1 column in 3 column table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Transpose-1-column-in-3-column-table/m-p/58678#M16484</link>
      <description>Hi:&lt;BR /&gt;
  You want PROC TRANSPOSE to summarize according to customer and department, but it's just not going to cooperate. This is really a job for one of the summary report procedures, like PROC REPORT or PROC TABULATE.&lt;BR /&gt;
&lt;BR /&gt;
  I'd probably pick REPORT, but that's because in the grand scheme of things, I'm probably more of a REPORT person than a TABULATE person.&lt;BR /&gt;
&lt;BR /&gt;
  To get the output into Excel, I'd choose either HTML file or a Spreadsheet Markup Language file, as shown in the code below. Although, you could make an output dataset from either REPORT or TAB and then use PROC EXPORT, if you wanted to.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
data product;&lt;BR /&gt;
 infile datalines;&lt;BR /&gt;
 input customer $ department product $;&lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
 001  300  Coffee &lt;BR /&gt;
 002  500  Tea &lt;BR /&gt;
 002  500  Tea &lt;BR /&gt;
 002  500  Coffee &lt;BR /&gt;
 003  700  Coffee &lt;BR /&gt;
 003  700  Tea &lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
                                &lt;BR /&gt;
title; footnote;&lt;BR /&gt;
ods listing close;&lt;BR /&gt;
options missing=0;&lt;BR /&gt;
                                    &lt;BR /&gt;
ods msoffice2k file='c:\temp\prod_HT.xls' style=sasweb;&lt;BR /&gt;
ods tagsets.excelxp file='c:\temp\prod_XP.xls' style=sasweb;&lt;BR /&gt;
                                   &lt;BR /&gt;
proc report data=product nowd;&lt;BR /&gt;
column ('With Proc Report' customer department)&lt;BR /&gt;
         n,product ;&lt;BR /&gt;
define customer / group ;&lt;BR /&gt;
define department / group;&lt;BR /&gt;
define product /across;&lt;BR /&gt;
define n / ' ';&lt;BR /&gt;
run;&lt;BR /&gt;
                                     &lt;BR /&gt;
proc tabulate data=product f=comma6.;&lt;BR /&gt;
class customer department product;&lt;BR /&gt;
table customer*department,&lt;BR /&gt;
      n*product /box='With Proc Tabulate';&lt;BR /&gt;
keylabel n=' ';&lt;BR /&gt;
run;&lt;BR /&gt;
                  &lt;BR /&gt;
ods _all_ close;&lt;BR /&gt;
&lt;BR /&gt;
                              &lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 30 Oct 2008 21:22:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Transpose-1-column-in-3-column-table/m-p/58678#M16484</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-10-30T21:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose 1 column in 3 column table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Transpose-1-column-in-3-column-table/m-p/58679#M16485</link>
      <description>Thank you very much Cynthia. You always help me &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;</description>
      <pubDate>Mon, 03 Nov 2008 10:43:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Transpose-1-column-in-3-column-table/m-p/58679#M16485</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-11-03T10:43:07Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose 1 column in 3 column table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Transpose-1-column-in-3-column-table/m-p/58680#M16486</link>
      <description>Hi Cynthia&lt;BR /&gt;
I am going to ask you about help again.&lt;BR /&gt;
Can you please explain how to rebuild this proc report to have data in following view:&lt;BR /&gt;
----------------------------------------------------------------------------&lt;BR /&gt;
PRODUCT | DEPARTMENT | CUSTOMER_COUNT | &lt;BR /&gt;
----------------------------------------------------------------------------&lt;BR /&gt;
Coffe | 300 | 3&lt;BR /&gt;
Tea   | 500 | 2</description>
      <pubDate>Mon, 03 Nov 2008 14:24:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Transpose-1-column-in-3-column-table/m-p/58680#M16486</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-11-03T14:24:41Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose 1 column in 3 column table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Transpose-1-column-in-3-column-table/m-p/58681#M16487</link>
      <description>Hi:&lt;BR /&gt;
  In this instance, you want to count or summarize the customers for each product, but within each product, you want to show the counts for each department. In Proc Report, this kind of summarizing is accomplished by defining a variable or variable as a GROUP variable. Since all you want is the COUNT, you can accomplish this by asking for the N statistic on the column statement:&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc report data=product nowd&lt;BR /&gt;
            split='#';&lt;BR /&gt;
  title 'Proc Report Counts for Product and Department';&lt;BR /&gt;
  column product department n;&lt;BR /&gt;
  define product /group 'Prod';&lt;BR /&gt;
  define department / group 'Dept';&lt;BR /&gt;
  define n / 'Customer#Count';&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Or, you could ask for the explicit count of customers with this version of the code, but for all intents and purposes, the count of all observations( example above) and the count of customers (example below) will get you the same results:&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc report data=product nowd;&lt;BR /&gt;
  title 'Proc Report Cross Customer with Count';&lt;BR /&gt;
  column product department customer,n;&lt;BR /&gt;
  define product /group 'Prod';&lt;BR /&gt;
  define department / group 'Dept';&lt;BR /&gt;
  define n / 'Count';&lt;BR /&gt;
  define customer / 'Customer';&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Mon, 03 Nov 2008 18:26:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Transpose-1-column-in-3-column-table/m-p/58681#M16487</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-11-03T18:26:24Z</dc:date>
    </item>
  </channel>
</rss>

