<?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 can I properly label the final table with state NAMES and have the % in the table in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/How-can-I-properly-label-the-final-table-with-state-NAMES-and/m-p/952786#M47675</link>
    <description>&lt;P&gt;Please show us a portion of your input data set. Please use these &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt; to provide the data as working SAS data step code. Please do NOT show us screen captures of data or provide data as Excel files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please also show us the desired output. This can be a screen capture if you wish.&lt;/P&gt;</description>
    <pubDate>Fri, 06 Dec 2024 22:02:57 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2024-12-06T22:02:57Z</dc:date>
    <item>
      <title>How can I properly label the final table with state NAMES and have the % in the table</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-can-I-properly-label-the-final-table-with-state-NAMES-and/m-p/952785#M47674</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;I am not getting any warnings in the log. &lt;/CODE&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-12-06 at 2.53.05 PM.png" style="width: 386px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102750i0EF89EB82A5CEC7D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-12-06 at 2.53.05 PM.png" alt="Screenshot 2024-12-06 at 2.53.05 PM.png" /&gt;&lt;/span&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=""&gt;/* Step 1: Use ODS OUTPUT to capture Chi-Square and Cross Tabulation results */
ods output ChiSq=chisqt_results; 
ods output CrossTabFreqs=cross_tab_results;

proc freq data=BRFSSAna.brfssanalysis;
  where not missing(Asthma_Status) and State in (8, 54); 
  tables State * Asthma_Status / chisq norow nocol nopercent;
  format State state.; /* Format State variable */
run;

/* Step 2: Inspect the Chi-square and Cross Tabulation results */
proc print data=chisqt_results; title "Chi-Square Test Results"; run; 
proc print data=cross_tab_results; title "Cross Tabulation Results"; run;

/* Step 3: Reshape the cross-tabulation data to combine frequency and percentage */
data cross_tab_results;
  set cross_tab_results;
  where _type_ = '11'; /* Include only observed values */
  /* Create a column with frequency and percentage (N(%)) */
  n_percent = strip(put(Frequency, 8.)) || " (" || strip(put(round(ColPercent, 0.1), 8.1)) || "%)"; 
run;

/* Step 4: Sort the cross-tabulation data by Asthma_Status and State */
proc sort data=cross_tab_results; by Asthma_Status State; run;

/* Step 5: Transpose the data for better presentation */
proc transpose data=cross_tab_results out=TransposedTable_freq(drop=_name_);
  by Asthma_Status;
  id State; /* Create columns for Colorado (8) and West Virginia (54) */
  var n_percent; /* Use N(%) as the variable for transposition */
run;

/* Step 6: Extract the p-value from Chi-Square results */
data pvalue;
  set chisqt_results;
  where Statistic = "Chi-Square"; /* Select Chi-Square statistic */
  keep Prob;
  rename Prob = p_value;
run;

/* Step 7: Add the p-value to the transposed table */
data FinalTable3;
  merge TransposedTable_freq pvalue;
  retain Asthma_Status State_8 State_54 p_value; /* Ensure proper column order */
  label State_8 = "Colorado (N (%))"
        State_54 = "West Virginia (N (%))"
        Asthma_Status = "Current Asthma Status"
        p_value = "P-Value";
run;

/* Step 8: Print the final table with p-value */
proc print data=FinalTable3; title "Final Table with P-value"; run;

/* Step 9: Make the table presentable using PROC REPORT */
proc report data=FinalTable3 nowd headline headskip split='/';
  column Asthma_Status ('State' State_8 State_54) p_value;
  define Asthma_Status / display "Asthma Status";
  define State_8 / "Colorado (N (%))";
  define State_54 / "West Virginia (N (%))";
  define p_value / "P-Value";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Dec 2024 21:54:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-can-I-properly-label-the-final-table-with-state-NAMES-and/m-p/952785#M47674</guid>
      <dc:creator>laurenekerr</dc:creator>
      <dc:date>2024-12-06T21:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: How can I properly label the final table with state NAMES and have the % in the table</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-can-I-properly-label-the-final-table-with-state-NAMES-and/m-p/952786#M47675</link>
      <description>&lt;P&gt;Please show us a portion of your input data set. Please use these &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt; to provide the data as working SAS data step code. Please do NOT show us screen captures of data or provide data as Excel files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please also show us the desired output. This can be a screen capture if you wish.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2024 22:02:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-can-I-properly-label-the-final-table-with-state-NAMES-and/m-p/952786#M47675</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-12-06T22:02:57Z</dc:date>
    </item>
    <item>
      <title>Re: How can I properly label the final table with state NAMES and have the % in the table</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-can-I-properly-label-the-final-table-with-state-NAMES-and/m-p/952807#M47676</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Remove the NOCOL from your TABLES statement if you want the ODS output dataset to have the COLPERCENT variable.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example using SASHELP.CLASS&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc format;
  value age low-12 = 'Pre Teen' 12-high = 'Teen' ;
run;

ods output ChiSq=chisqt_results; 
ods output CrossTabFreqs=cross_tab_results;

proc freq data=sashelp.class;
  tables age * sex / chisq norow nocol nopercent;
  format age age.;
run;

proc print data=chisqt_results; run;
proc print data=cross_tab_results; run;

/* Include only observed values */
/* Create a column with frequency and percentage (N(%)) */
data cross_tab_results2;
  set cross_tab_results;
  where _type_ = '11'; 
  n_percent = strip(put(Frequency, 8.)) || " (" || strip(put(round(ColPercent, 0.1), 8.1)) || "%)"; 
run;

proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;Notice this line in the log&lt;/P&gt;
&lt;PRE&gt;NOTE: Variable ColPercent is uninitialized.
&lt;/PRE&gt;
&lt;P&gt;Here is the PROC CONTENTS for that dataset. There is no percentage column there.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1733525174738.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102769i533A8A30E2EC4189/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1733525174738.png" alt="Tom_0-1733525174738.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Change the TABLES statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;tables State * Asthma_Status / chisq norow /*nocol*/ nopercent;&lt;/CODE&gt;&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>Sat, 07 Dec 2024 02:43:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-can-I-properly-label-the-final-table-with-state-NAMES-and/m-p/952807#M47676</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-07T02:43:51Z</dc:date>
    </item>
    <item>
      <title>Re: How can I properly label the final table with state NAMES and have the % in the table</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-can-I-properly-label-the-final-table-with-state-NAMES-and/m-p/952920#M47689</link>
      <description>&lt;P&gt;I am going to ask a very pointed question about WHY you are using Proc FREQ at all? And completely ignoring weights associated with the records?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The BRFSS data is from a complex survey sample. As such one of the procedures that can use the complex weighting design are appropriate, in this case Proc SurveyFreq.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 03:56:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-can-I-properly-label-the-final-table-with-state-NAMES-and/m-p/952920#M47689</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-12-09T03:56:23Z</dc:date>
    </item>
  </channel>
</rss>

