- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please show us a portion of your input data set. Please use these examples and instructions 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.
Please also show us the desired output. This can be a screen capture if you wish.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Remove the NOCOL from your TABLES statement if you want the ODS output dataset to have the COLPERCENT variable.
Here is an example using SASHELP.CLASS
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;
Notice this line in the log
NOTE: Variable ColPercent is uninitialized.
Here is the PROC CONTENTS for that dataset. There is no percentage column there.
Change the TABLES statement:
tables State * Asthma_Status / chisq norow /*nocol*/ nopercent;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
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.