I am not getting any warnings in the log. /* 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;
... View more