<?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 export select results to an excel file in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/how-to-export-select-results-to-an-excel-file/m-p/411692#M19827</link>
    <description>&lt;P&gt;There are two parts to your question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, how to create a dataset that contains what you want. The following will work with your example data:&lt;/P&gt;
&lt;PRE&gt;proc freq data=raw_data;
  table year * alcohol_use year*tobacco_use year*marijuana_use/ nopercent nocol chisq;
  ods output CrossTabFreqs=freq;
  ods output ChiSq=chi;
run;

data want (keep=outcome year count: percent:);
  set freq (where=(_TYPE_ eq '11' and
     (alcohol_use eq 1 or tobacco_use eq 1 or marijuana_use eq 1) and
     year in (2008,2016)));
  length outcome $12;
  retain count2008 percent2008;
  outcome=substr(table,14);
  if year eq 2008 then do;
    count2008=frequency;
    percent2008=rowpercent;
  end;
  else do;
    count2016=frequency;
    percent2016=rowpercent;
    output;
  end;
run;

data want (drop=statistic);
  set want;
  set chi (where=(statistic eq 'Chi-Square')
    keep=statistic prob);
run;
&lt;/PRE&gt;
&lt;P&gt;You can use a number of ways to get that into excel, e.g., proc export.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 08 Nov 2017 20:52:59 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-11-08T20:52:59Z</dc:date>
    <item>
      <title>how to export select results to an excel file</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/how-to-export-select-results-to-an-excel-file/m-p/411655#M19822</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have data for 2 different years - 2008 and 2016 - on whether people living in a particular community use different substances such as alcohol, tobacco etc (yes/no variable coded as 0=No, 1=Yes).&lt;/P&gt;
&lt;P&gt;Have (raw data):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data WORK.RAW_DATA(label='raw_data dataset written by Stat/Transfer Ver. 11.2.2106.0521       ');
  infile datalines dsd truncover;
  input Community_name:$1. Year:32. Alcohol_use:32. Tobacco_use:32. Marijuana_use:32.;
datalines4;
A,2008,1,1,0
A,2008,1,1,1
A,2008,1,0,1
A,2008,1,1,1
A,2008,1,1,1
A,2008,0,0,1
A,2008,0,0,1
A,2008,1,0,0
A,2008,0,1,0
A,2008,1,1,1
A,2008,0,0,1
A,2008,0,1,1
A,2008,0,1,1
A,2008,0,0,0
A,2008,1,1,1
A,2008,1,1,0
A,2008,1,1,1
A,2008,0,0,0
A,2008,0,1,1
A,2008,1,1,1
A,2016,1,0,0
A,2016,1,0,1
A,2016,0,0,0
A,2016,0,0,0
A,2016,1,1,0
A,2016,1,1,1
A,2016,1,1,1
A,2016,0,0,0
A,2016,0,0,0
A,2016,0,1,0
A,2016,0,0,1
A,2016,1,1,1
A,2016,0,1,1
A,2016,0,1,1
A,2016,0,0,0
A,2016,1,1,1
A,2016,0,0,0
A,2016,1,1,1
A,2016,0,0,0
A,2016,1,1,1
A,2016,1,0,1
A,2016,0,1,0
A,2016,0,0,0
A,2016,0,0,0
A,2016,0,1,0
;;;;
&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;I am using chi-square to analyze the data for each community using the following code in SAS 9.4:&lt;/P&gt;
&lt;P&gt;proc freq data=raw_data;&lt;/P&gt;
&lt;P&gt;table year * alcohol_use year*tobacco_use year*marijuana_use/ nopercent nocolumn chisq;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The results are attached.&lt;/P&gt;
&lt;P&gt;I am interested in the freq count and row percentages for the yes responses coded "1" in 2008 and 2016, and predicted probability of chi-square value (highlighted in the resutls). Is there a way to export just the highlighted results to an excel file instead of having to manually enter the numbers or copy/paste for all the outcomes?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Want (summary statistics):&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="130"&gt;
&lt;P&gt;Outcome&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="130"&gt;
&lt;P&gt;2008count&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="130"&gt;
&lt;P&gt;2008percent&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="130"&gt;
&lt;P&gt;2016count&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="130"&gt;
&lt;P&gt;2016percent&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="130"&gt;
&lt;P&gt;prob&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="130"&gt;
&lt;P&gt;Alcohol_use&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="130"&gt;
&lt;P&gt;12&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="130"&gt;
&lt;P&gt;57.14&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="130"&gt;
&lt;P&gt;10&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="130"&gt;
&lt;P&gt;40.00&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="130"&gt;
&lt;P&gt;0.2463&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="130"&gt;
&lt;P&gt;Tobacco_use&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="130"&gt;
&lt;P&gt;14&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="130"&gt;
&lt;P&gt;66.67&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="130"&gt;
&lt;P&gt;12&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="130"&gt;
&lt;P&gt;48.00&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="130"&gt;
&lt;P&gt;0.2033&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="130"&gt;
&lt;P&gt;Marijuana_use&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="130"&gt;
&lt;P&gt;15&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="130"&gt;
&lt;P&gt;71.43&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="130"&gt;
&lt;P&gt;11&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="130"&gt;
&lt;P&gt;44.00&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="130"&gt;
&lt;P&gt;0.0616&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any suggestions?&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2017 21:26:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/how-to-export-select-results-to-an-excel-file/m-p/411655#M19822</guid>
      <dc:creator>Angi</dc:creator>
      <dc:date>2017-11-08T21:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: how to export select results to an excel file</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/how-to-export-select-results-to-an-excel-file/m-p/411666#M19823</link>
      <description>&lt;P&gt;Please provide example data in the form of a datastep if you would like example code. If you don't know how to create such a datastep Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2017 20:00:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/how-to-export-select-results-to-an-excel-file/m-p/411666#M19823</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-11-08T20:00:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to export select results to an excel file</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/how-to-export-select-results-to-an-excel-file/m-p/411692#M19827</link>
      <description>&lt;P&gt;There are two parts to your question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, how to create a dataset that contains what you want. The following will work with your example data:&lt;/P&gt;
&lt;PRE&gt;proc freq data=raw_data;
  table year * alcohol_use year*tobacco_use year*marijuana_use/ nopercent nocol chisq;
  ods output CrossTabFreqs=freq;
  ods output ChiSq=chi;
run;

data want (keep=outcome year count: percent:);
  set freq (where=(_TYPE_ eq '11' and
     (alcohol_use eq 1 or tobacco_use eq 1 or marijuana_use eq 1) and
     year in (2008,2016)));
  length outcome $12;
  retain count2008 percent2008;
  outcome=substr(table,14);
  if year eq 2008 then do;
    count2008=frequency;
    percent2008=rowpercent;
  end;
  else do;
    count2016=frequency;
    percent2016=rowpercent;
    output;
  end;
run;

data want (drop=statistic);
  set want;
  set chi (where=(statistic eq 'Chi-Square')
    keep=statistic prob);
run;
&lt;/PRE&gt;
&lt;P&gt;You can use a number of ways to get that into excel, e.g., proc export.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2017 20:52:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/how-to-export-select-results-to-an-excel-file/m-p/411692#M19827</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-11-08T20:52:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to export select results to an excel file</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/how-to-export-select-results-to-an-excel-file/m-p/411718#M19828</link>
      <description>Thank you for your suggestion! I have updated my original post with sample data in the form of a datastep.</description>
      <pubDate>Wed, 08 Nov 2017 21:44:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/how-to-export-select-results-to-an-excel-file/m-p/411718#M19828</guid>
      <dc:creator>Angi</dc:creator>
      <dc:date>2017-11-08T21:44:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to export select results to an excel file</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/how-to-export-select-results-to-an-excel-file/m-p/411726#M19829</link>
      <description>This worked!!!! Thank you very much for your help!!!!</description>
      <pubDate>Wed, 08 Nov 2017 22:01:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/how-to-export-select-results-to-an-excel-file/m-p/411726#M19829</guid>
      <dc:creator>Angi</dc:creator>
      <dc:date>2017-11-08T22:01:48Z</dc:date>
    </item>
  </channel>
</rss>

