<?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 Output Chi Square and Fisher's exact in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Output-Chi-Square-and-Fisher-s-exact/m-p/891756#M352256</link>
    <description>&lt;P&gt;Using SAS 9.4.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following code. Is there a way to edit the macro to enable a list of xvars instead of having to list each new xvar? I have 20+ variables and it would be nice to not have to write those out. Thank you&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro getChiFish(data=, xvar=, grpvar=, outDat=);	
	proc freq data=&amp;amp;data noprint;
		Tables &amp;amp;xvar * &amp;amp;grpvar/ missing nocum chisq fisher nopercent norow;
		output out=tmpDat n nmiss pchi lrchi fisher ;
	run;
	%LET tmpvar = &amp;amp;xvar;
	data &amp;amp;outDat;
		set tmpDat (keep = P_PCHI XP2_FISH);
		varN = symget('tmpvar');
	run;
%mend getChiFish;
%getChiFish(data=para.analysis, xvar=sex, grpvar=recur, outDat=pval1) 
%getChiFish(data=para.analysis, xvar=race, grpvar=recur, outDat=pval2) 
%getChiFish(data=para.analysis, xvar=procedureid, grpvar=recur, outDat=pval3)
%getChiFish(data=para.analysis, xvar=proc_technique, grpvar=recur, outDat=pval4)
%getChiFish(data=para.analysis, xvar=smoke, grpvar=recur, outDat=pval5)&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 30 Aug 2023 17:33:38 GMT</pubDate>
    <dc:creator>GS2</dc:creator>
    <dc:date>2023-08-30T17:33:38Z</dc:date>
    <item>
      <title>Output Chi Square and Fisher's exact</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-Chi-Square-and-Fisher-s-exact/m-p/891756#M352256</link>
      <description>&lt;P&gt;Using SAS 9.4.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following code. Is there a way to edit the macro to enable a list of xvars instead of having to list each new xvar? I have 20+ variables and it would be nice to not have to write those out. Thank you&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro getChiFish(data=, xvar=, grpvar=, outDat=);	
	proc freq data=&amp;amp;data noprint;
		Tables &amp;amp;xvar * &amp;amp;grpvar/ missing nocum chisq fisher nopercent norow;
		output out=tmpDat n nmiss pchi lrchi fisher ;
	run;
	%LET tmpvar = &amp;amp;xvar;
	data &amp;amp;outDat;
		set tmpDat (keep = P_PCHI XP2_FISH);
		varN = symget('tmpvar');
	run;
%mend getChiFish;
%getChiFish(data=para.analysis, xvar=sex, grpvar=recur, outDat=pval1) 
%getChiFish(data=para.analysis, xvar=race, grpvar=recur, outDat=pval2) 
%getChiFish(data=para.analysis, xvar=procedureid, grpvar=recur, outDat=pval3)
%getChiFish(data=para.analysis, xvar=proc_technique, grpvar=recur, outDat=pval4)
%getChiFish(data=para.analysis, xvar=smoke, grpvar=recur, outDat=pval5)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Aug 2023 17:33:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-Chi-Square-and-Fisher-s-exact/m-p/891756#M352256</guid>
      <dc:creator>GS2</dc:creator>
      <dc:date>2023-08-30T17:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: Output Chi Square and Fisher's exact</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-Chi-Square-and-Fisher-s-exact/m-p/891758#M352257</link>
      <description>&lt;P&gt;The general method of figuring out how to do this, for almost every PROC, is to use ODS TRACE. Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods trace on;
proc freq data=sashelp.class;
    tables sex*age/chisq exact;
run;
ods trace off;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the log you will see:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Output Added:
-------------
Name:       CrossTabFreqs
Label:      Cross-Tabular Freq Table
Template:   Base.Freq.CrossTabFreqs
Path:       Freq.Table1.CrossTabFreqs
-------------

Output Added:
-------------
Name:       ChiSq
Label:      Chi-Square Tests
Template:   Base.Freq.ChiSq
Path:       Freq.Table1.ChiSq
-------------

Output Added:
-------------
Name:       FishersExact
Label:      Fisher's Exact Test
Template:   Base.Freq.ChisqExactFactoid
Path:       Freq.Table1.FishersExact
-------------
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so these are the names of the tables in SAS you want to output to a data set. Use ODS OUTPUT like this, where to the left of the equal signs are the table names shown above, and to the right of the equal signs are the name of the SAS data set you want to create.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods output chisq=chi_squared fishersexact=fisher;
proc freq data=sashelp.class;
    tables sex*age/chisq exact;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2023 17:45:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-Chi-Square-and-Fisher-s-exact/m-p/891758#M352257</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-30T17:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: Output Chi Square and Fisher's exact</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-Chi-Square-and-Fisher-s-exact/m-p/891800#M352270</link>
      <description>&lt;P&gt;I am going to say "GAAACK!".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There really is no reason to load the data set into Proc freq that many times. () will group variables together in proc freq.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;	proc freq data=&amp;amp;data noprint;
		Tables (xvarlist) * (grpvarlist)/ missing nocum chisq fisher nopercent norow;
		output out=tmpDat n nmiss pchi lrchi fisher ;
	run;&lt;/PRE&gt;
&lt;P&gt;So if you use&lt;/P&gt;
&lt;PRE&gt;ods output chisq=chi_squared fishersexact=fisher;&lt;BR /&gt;proc freq data=&amp;amp;data noprint;
   Tables (sex race procedureid proc_techique smoke) * (recur)/ missing nocum chisq fisher nopercent norow;
run;&lt;/PRE&gt;
&lt;P&gt;You get all the analysis in one pass. Use ODS OUTPUT with the desired tables as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; has shown and all of the results go into data sets with information to extract as needed such as table identification, variables used and the results.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2023 19:38:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-Chi-Square-and-Fisher-s-exact/m-p/891800#M352270</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-30T19:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: Output Chi Square and Fisher's exact</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-Chi-Square-and-Fisher-s-exact/m-p/891801#M352271</link>
      <description>&lt;P&gt;Adding to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;'s comment, you might want the NOPRINT option in the TABLES statement as well (or maybe you don't want the NOPRINT option, its up to you, but typically when you are outputting to data sets, you don't also need the same output in the Results window).&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2023 19:44:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-Chi-Square-and-Fisher-s-exact/m-p/891801#M352271</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-30T19:44:47Z</dc:date>
    </item>
    <item>
      <title>Re: Output Chi Square and Fisher's exact</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-Chi-Square-and-Fisher-s-exact/m-p/891840#M352288</link>
      <description>&lt;P&gt;ODS output requires the result output. Otherwise you're restricted to the old OUTPUT statement limit of only the last table generated would create a dataset. Which would lead us to multiple TABLE statements and separate output data sets for each.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2023 01:57:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-Chi-Square-and-Fisher-s-exact/m-p/891840#M352288</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-31T01:57:41Z</dc:date>
    </item>
  </channel>
</rss>

