<?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: restructuring two-way tables with variable on left and statistic along top in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/restructuring-two-way-tables-with-variable-on-left-and-statistic/m-p/72257#M20927</link>
    <description>Do you know how to do the same with text where the yes/no answer is stored in the varx?  &lt;BR /&gt;
------|--Group1-------|-----|--Group2-------|&lt;BR /&gt;
----- |--no--| |--yes--|-----|--no--| |--yes--|&lt;BR /&gt;
var1&lt;BR /&gt;
var2</description>
    <pubDate>Wed, 23 Sep 2009 13:31:57 GMT</pubDate>
    <dc:creator>donevans</dc:creator>
    <dc:date>2009-09-23T13:31:57Z</dc:date>
    <item>
      <title>restructuring two-way tables with variable on left and statistic along top</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/restructuring-two-way-tables-with-variable-on-left-and-statistic/m-p/72251#M20921</link>
      <description>Is there a way to restructure a two-way table so that the variable name is on the left and statistic along the top?  &lt;BR /&gt;
&lt;BR /&gt;
Example:&lt;BR /&gt;
                           ------ |-------  Group1 ---------|   |------------- Group 2 -----------|&lt;BR /&gt;
                           ------   n   mean   median    max      n   mean    median  max&lt;BR /&gt;
var1&lt;BR /&gt;
var2&lt;BR /&gt;
var3</description>
      <pubDate>Fri, 18 Sep 2009 18:07:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/restructuring-two-way-tables-with-variable-on-left-and-statistic/m-p/72251#M20921</guid>
      <dc:creator>donevans</dc:creator>
      <dc:date>2009-09-18T18:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: restructuring two-way tables with variable on left and statistic along top</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/restructuring-two-way-tables-with-variable-on-left-and-statistic/m-p/72252#M20922</link>
      <description>Have you looked at PROC TABULATE?&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 18 Sep 2009 18:21:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/restructuring-two-way-tables-with-variable-on-left-and-statistic/m-p/72252#M20922</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-09-18T18:21:10Z</dc:date>
    </item>
    <item>
      <title>Re: restructuring two-way tables with variable on left and statistic along top</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/restructuring-two-way-tables-with-variable-on-left-and-statistic/m-p/72253#M20923</link>
      <description>Yes, I use proc tabulate to get the following result.  It's easier to compare if all of the statistics were listed across the top instead of under each of the variable names.&lt;BR /&gt;
-------- |--- Group1 -----| |----- Group2------|&lt;BR /&gt;
var1 &lt;BR /&gt;
n&lt;BR /&gt;
mean&lt;BR /&gt;
median&lt;BR /&gt;
max&lt;BR /&gt;
var2&lt;BR /&gt;
n&lt;BR /&gt;
mean&lt;BR /&gt;
median&lt;BR /&gt;
max&lt;BR /&gt;
var3&lt;BR /&gt;
n</description>
      <pubDate>Fri, 18 Sep 2009 18:35:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/restructuring-two-way-tables-with-variable-on-left-and-statistic/m-p/72253#M20923</guid>
      <dc:creator>donevans</dc:creator>
      <dc:date>2009-09-18T18:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: restructuring two-way tables with variable on left and statistic along top</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/restructuring-two-way-tables-with-variable-on-left-and-statistic/m-p/72254#M20924</link>
      <description>I'd recommend searching the SAS support  &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;  website for examples based on technical and conference topic-related references.  Google advanced search (using the parameter site:sas.com) or the support site's SEARCH facility are very helpful with finding these opportunities, as well as the SAS-hosted product documentation which includes examples.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 18 Sep 2009 18:44:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/restructuring-two-way-tables-with-variable-on-left-and-statistic/m-p/72254#M20924</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-09-18T18:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: restructuring two-way tables with variable on left and statistic along top</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/restructuring-two-way-tables-with-variable-on-left-and-statistic/m-p/72255#M20925</link>
      <description>Hi:&lt;BR /&gt;
  It may be as easy as moving your statistics from the row dimension to the column dimension, as shown in the program below.&lt;BR /&gt;
 &lt;BR /&gt;
  The first PROC TABULATE shows the statistics nested in the row dimension; while the second PROC TABULATE shows the statistics nested in the column dimension.&lt;BR /&gt;
 &lt;BR /&gt;
  cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
                          &lt;BR /&gt;
** make some data;&lt;BR /&gt;
data prdsale;&lt;BR /&gt;
  set sashelp.prdsale;&lt;BR /&gt;
  if division = 'CONSUMER' then group = 'Group 1';&lt;BR /&gt;
  else group = 'Group 2';&lt;BR /&gt;
run;&lt;BR /&gt;
                            &lt;BR /&gt;
ods html file='c:\temp\tabvars.html' style=sasweb;&lt;BR /&gt;
proc tabulate data=prdsale;&lt;BR /&gt;
  title 'One Way';&lt;BR /&gt;
  class group;&lt;BR /&gt;
  var actual predict;&lt;BR /&gt;
  table actual*(n mean median max) predict*(n mean median max),&lt;BR /&gt;
        group=' ';&lt;BR /&gt;
run;&lt;BR /&gt;
                        &lt;BR /&gt;
proc tabulate data=prdsale;&lt;BR /&gt;
  title 'Another Way';&lt;BR /&gt;
  class group;&lt;BR /&gt;
  var actual predict;&lt;BR /&gt;
  table actual predict,&lt;BR /&gt;
        group=' '*(n mean median max);&lt;BR /&gt;
run;&lt;BR /&gt;
ods html close;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Sat, 19 Sep 2009 02:53:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/restructuring-two-way-tables-with-variable-on-left-and-statistic/m-p/72255#M20925</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-09-19T02:53:48Z</dc:date>
    </item>
    <item>
      <title>Re: restructuring two-way tables with variable on left and statistic along top</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/restructuring-two-way-tables-with-variable-on-left-and-statistic/m-p/72256#M20926</link>
      <description>Thanks.  This worked.  I had added an extra "all" between the "predict" variable and comma, so I was trying to run stats on a stat.  Needless to say, SAS did not like that.</description>
      <pubDate>Tue, 22 Sep 2009 12:50:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/restructuring-two-way-tables-with-variable-on-left-and-statistic/m-p/72256#M20926</guid>
      <dc:creator>donevans</dc:creator>
      <dc:date>2009-09-22T12:50:30Z</dc:date>
    </item>
    <item>
      <title>Re: restructuring two-way tables with variable on left and statistic along top</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/restructuring-two-way-tables-with-variable-on-left-and-statistic/m-p/72257#M20927</link>
      <description>Do you know how to do the same with text where the yes/no answer is stored in the varx?  &lt;BR /&gt;
------|--Group1-------|-----|--Group2-------|&lt;BR /&gt;
----- |--no--| |--yes--|-----|--no--| |--yes--|&lt;BR /&gt;
var1&lt;BR /&gt;
var2</description>
      <pubDate>Wed, 23 Sep 2009 13:31:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/restructuring-two-way-tables-with-variable-on-left-and-statistic/m-p/72257#M20927</guid>
      <dc:creator>donevans</dc:creator>
      <dc:date>2009-09-23T13:31:57Z</dc:date>
    </item>
    <item>
      <title>Re: restructuring two-way tables with variable on left and statistic along top</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/restructuring-two-way-tables-with-variable-on-left-and-statistic/m-p/72258#M20928</link>
      <description>Hi:&lt;BR /&gt;
  What is a VARX??? Do you have 2 variables -- GROUP1 with values of YES and NO and then GROUP2 with values of YES and NO or do you have 1 variable with values of either GROUP1 or GROUP2???&lt;BR /&gt;
 &lt;BR /&gt;
  In the situation you describe, would the variables going down the rows still be numeric variables (what you show as VAR1 and VAR2)? Or would they be category variables (like COUNTRY or REGION for example)?? &lt;BR /&gt;
 &lt;BR /&gt;
  It might help to see a little sample of data. For example, I can envision at least 2 possible ways that your data could be structured:&lt;BR /&gt;
  &lt;BR /&gt;
Possibility A:&lt;BR /&gt;
[pre]&lt;BR /&gt;
VARA  VARB   GROUP1   GROUP2  NVAR1   NVAR2&lt;BR /&gt;
xxx    yyy    yes       no     111      221&lt;BR /&gt;
xxx    yyy    no        no     112      222  &lt;BR /&gt;
xxx    yyy    no        yes    113      223&lt;BR /&gt;
aaa    bbb    yes       yes    114      224&lt;BR /&gt;
aaa    bbb    no        no     115      225&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                                 &lt;BR /&gt;
and&lt;BR /&gt;
Possibility B:&lt;BR /&gt;
[pre]&lt;BR /&gt;
VARA   VARB   GROUP     RESP    NVAR&lt;BR /&gt;
xxx    yyy   GROUP1     yes     111 &lt;BR /&gt;
xxx    yyy   GROUP2     no      221&lt;BR /&gt;
xxx    yyy   GROUP1     no      112&lt;BR /&gt;
xxx    yyy   GROUP2     no      222&lt;BR /&gt;
xxx    yyy   GROUP1     no      113&lt;BR /&gt;
xxx    yyy   GROUP2     yes     223&lt;BR /&gt;
aaa    bbb   GROUP1     yes     114&lt;BR /&gt;
aaa    bbb   GROUP2     yes     224&lt;BR /&gt;
aaa    bbb   GROUP1     no      115     &lt;BR /&gt;
aaa    bbb   GROUP2     no      225&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                            &lt;BR /&gt;
If you look at SASHELP.PRDSALE, you will see that it has numeric variables ACTUAL and PREDICT and then the DIVISION variable has values of CONSUMER or EDUCATION and the REGION variable has the values of EAST or WEST. COUNTRY has 3 possible values. The example program below shows the difference between using ACTUAL and PREDICT in the ROW dimension (table 1) versus using all category variables in the ROW and COL dimensions (table 2) versus using a numeric variable nested with the category variables in the COL dimension (table 3).&lt;BR /&gt;
 &lt;BR /&gt;
  If you look at SASHELP.PRDSALE and compare the structure of its data to the structure of your data, you may get some ideas of how to plug your variables into this sample program. &lt;BR /&gt;
&lt;BR /&gt;
cynthia&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
ods html file='c:\temp\catvars.html' style=sasweb;&lt;BR /&gt;
                    &lt;BR /&gt;
proc tabulate data=sashelp.prdsale;&lt;BR /&gt;
  title '1) Sum of Numeric Vars In the Cells';&lt;BR /&gt;
  class division region;&lt;BR /&gt;
  var actual predict;&lt;BR /&gt;
  table actual predict,&lt;BR /&gt;
        division region all;&lt;BR /&gt;
run;&lt;BR /&gt;
                   &lt;BR /&gt;
proc tabulate data=sashelp.prdsale;&lt;BR /&gt;
  title '2) Count of Category Variables in the Cells';&lt;BR /&gt;
  class division region country;&lt;BR /&gt;
  table country all,&lt;BR /&gt;
        division region all;&lt;BR /&gt;
run;&lt;BR /&gt;
                              &lt;BR /&gt;
proc tabulate data=sashelp.prdsale;&lt;BR /&gt;
  title '3) Sum of Actual in the Cells';&lt;BR /&gt;
  class division region country;&lt;BR /&gt;
  var actual;&lt;BR /&gt;
  table country all,&lt;BR /&gt;
        actual*(division region all);&lt;BR /&gt;
run;&lt;BR /&gt;
ods html close;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 23 Sep 2009 15:02:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/restructuring-two-way-tables-with-variable-on-left-and-statistic/m-p/72258#M20928</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-09-23T15:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: restructuring two-way tables with variable on left and statistic along top</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/restructuring-two-way-tables-with-variable-on-left-and-statistic/m-p/72259#M20929</link>
      <description>My data looks something like this (1st row are the variable names):&lt;BR /&gt;
&lt;BR /&gt;
group---var1---var2---var3---var4......&lt;BR /&gt;
group1--no----yes----yes---no&lt;BR /&gt;
group2--yes--no-----yes----yes&lt;BR /&gt;
&lt;BR /&gt;
I want to do something like a frequency count (like proc freq, but transposed--frequencies and all possible response only) where the name of the variable is on the left side and there are three columns (yes,no,blank) with the count for each response to the right of the variable name.&lt;BR /&gt;
The table examples you provided will list the variable name (on the 1st row) along the left as well as the possible responses in the 2nd(blank), 3rd(no) and 4th(yes) rows.&lt;BR /&gt;
Once I understand how to do this "one-way" table, I want to add the "group" to the top for the "two-way" dimension.&lt;BR /&gt;
&lt;BR /&gt;
------|--Group1-------|-----|--Group2-------|&lt;BR /&gt;
----- |--no--| |--yes--|-----|--no--| |--yes--|&lt;BR /&gt;
var1&lt;BR /&gt;
var2 &lt;BR /&gt;
var3&lt;BR /&gt;
var4</description>
      <pubDate>Wed, 23 Sep 2009 17:09:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/restructuring-two-way-tables-with-variable-on-left-and-statistic/m-p/72259#M20929</guid>
      <dc:creator>donevans</dc:creator>
      <dc:date>2009-09-23T17:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: restructuring two-way tables with variable on left and statistic along top</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/restructuring-two-way-tables-with-variable-on-left-and-statistic/m-p/72260#M20930</link>
      <description>Hi:&lt;BR /&gt;
  It would be easier to do what you want if your data were in a different structure. something like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
group     id    varname    varval&lt;BR /&gt;
               &lt;BR /&gt;
group1    A      var1       no&lt;BR /&gt;
group1    A      var2       yes&lt;BR /&gt;
group1    A      var3       yes&lt;BR /&gt;
group1    A      var4       no&lt;BR /&gt;
group2    A      var1       yes&lt;BR /&gt;
group2    A      var2       no&lt;BR /&gt;
group2    A      var3       yes&lt;BR /&gt;
group2    A      var4       yes&lt;BR /&gt;
group1    B      var1&lt;BR /&gt;
group1    B      var2       yes&lt;BR /&gt;
group1    B      var3       yes&lt;BR /&gt;
group1    B      var4       no&lt;BR /&gt;
group2    B      var1       yes&lt;BR /&gt;
group2    B      var2&lt;BR /&gt;
group2    B      var3       yes&lt;BR /&gt;
group2    B      var4       no&lt;BR /&gt;
group1    C      var1       no&lt;BR /&gt;
group1    C      var2       no&lt;BR /&gt;
group1    C      var3&lt;BR /&gt;
group1    C      var4       no&lt;BR /&gt;
group2    C      var1       yes&lt;BR /&gt;
group2    C      var2       no&lt;BR /&gt;
group2    C      var3       yes&lt;BR /&gt;
group2    C      var4&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                    &lt;BR /&gt;
(Note that this fake data also has an ID variable, which your data may or may not have.)&lt;BR /&gt;
                  &lt;BR /&gt;
Once the data are in this structure, you could use a PROC TABULATE like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
ods listing close;&lt;BR /&gt;
ods html file='newgrp.html' style=sasweb;&lt;BR /&gt;
options missing = 0;&lt;BR /&gt;
proc tabulate data=newgrp f=comma7.;&lt;BR /&gt;
  title '4) Using VARNAME and VARVAL';&lt;BR /&gt;
  class group varname varval / missing;&lt;BR /&gt;
  table varname=' ' all,&lt;BR /&gt;
        group=' '*varval=' ' all;&lt;BR /&gt;
  keylabel n=' ';&lt;BR /&gt;
run;      &lt;BR /&gt;
ods html close;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                                 &lt;BR /&gt;
  So, how do you get from your current structure to the new structure? I'd use either a data step program and array processing or proc transpose. I think the data step approach is probably simpler to understand. That transformation and the entire program is shown below.&lt;BR /&gt;
                  &lt;BR /&gt;
cynthia &lt;BR /&gt;
[pre]&lt;BR /&gt;
data testgrp;&lt;BR /&gt;
  infile datalines dlm='-';&lt;BR /&gt;
  input group $ var1 $ var2 $ var3 $ var4 $ id $;&lt;BR /&gt;
  return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
group1--no--yes--yes--no--A&lt;BR /&gt;
group2--yes--no--yes--yes--A&lt;BR /&gt;
group1--.--yes--yes--no--B&lt;BR /&gt;
group2--yes--.--yes--no--B&lt;BR /&gt;
group1--no--no--.--no--C&lt;BR /&gt;
group2--yes--no--yes--.--C&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
                       &lt;BR /&gt;
options nocenter;&lt;BR /&gt;
                 &lt;BR /&gt;
ods listing;&lt;BR /&gt;
proc print data=testgrp;&lt;BR /&gt;
  title 'current structure';&lt;BR /&gt;
run;&lt;BR /&gt;
                 &lt;BR /&gt;
data newgrp;&lt;BR /&gt;
  set testgrp;&lt;BR /&gt;
  array vn $3 var1-var4;&lt;BR /&gt;
  do i = 1 to 4 by 1;&lt;BR /&gt;
    varname = cat('var',put(i,1.0));&lt;BR /&gt;
    varval = vn(i);&lt;BR /&gt;
    output;&lt;BR /&gt;
  end;&lt;BR /&gt;
  drop var1-var4 i;&lt;BR /&gt;
run;&lt;BR /&gt;
                              &lt;BR /&gt;
proc print data=newgrp noobs;&lt;BR /&gt;
  title 'new structure';&lt;BR /&gt;
run;&lt;BR /&gt;
                      &lt;BR /&gt;
ods listing close;&lt;BR /&gt;
ods html file='newgrp.html' style=sasweb;&lt;BR /&gt;
options missing = 0;&lt;BR /&gt;
proc tabulate data=newgrp f=comma7.;&lt;BR /&gt;
  title '4) Using VARNAME and VARVAL';&lt;BR /&gt;
  class group varname varval / missing;&lt;BR /&gt;
  table varname=' ' all,&lt;BR /&gt;
        group=' '*varval=' ' all;&lt;BR /&gt;
  keylabel n=' ';&lt;BR /&gt;
run;      &lt;BR /&gt;
ods html close;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 23 Sep 2009 18:57:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/restructuring-two-way-tables-with-variable-on-left-and-statistic/m-p/72260#M20930</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-09-23T18:57:45Z</dc:date>
    </item>
  </channel>
</rss>

