DATA Step, Macro, Functions and more

How to create an output including row & total percentages from a 2 by 2 frequency table & Stats

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

How to create an output including row & total percentages from a 2 by 2 frequency table & Stats

I have ran FREQ Procedure to get a 2 by 2 frequency table and Chi Square Statistics for 20 measures. I'd like to create an output to include only row percentages for each category and total percentages from the frequency table, and Pearson chi-square statistics together. Now I only generated an output for Chi Square Stats. Is there any functions I can use to get the final result like the table below? Thanks a lot in advance.

 

MEASURE_IDN_PCHI_P_PCHICATEGORY_1_PCT_ROWCATEGORY_2_PCT_ROWTOTAL _PCT_ROW
2750.6985780.40326191   
3162550.0206130.88583941   
424002.2890160.13029252   

 

PROC FREQ DATA = DATASET;

BY MEASURE_ID;

TABLE ETHNICITY * COMP_IND/CHISQ ;

OUTPUT OUT=ChiSqData_V1 N PCHI;

WEIGHT COUNT;

RUN;

 

PROC PRINT DATA=ChiSqData_V1 noobs ;

RUN;

 


Accepted Solutions
Solution
‎10-13-2016 11:30 AM
Super User
Posts: 9,671

Re: How to create an output including row & total percentages from a 2 by 2 frequency table &amp

Can you post your data and the output.

I think you can use SQL to get that row_pct , after using proc freq to get that Chisquare,

you can combine them together into one table.

View solution in original post


All Replies
Super User
Posts: 10,474

Re: How to create an output including row & total percentages from a 2 by 2 frequency table &amp

You may need to provide some example data with calculated percentages as you need them. I am not sure at the moment what CATEGORY_1_PCT_ROW is actually. OR as a very bare minimum provide what is included in the numerator and denominator for the percentages. You may well have to have more than one data set and combine them.

 

You can get the row and column percentages by using the OUT= option on the TABLES statement with OUTPCT. Depending on what you are doing OUTEXPECT to get the expected frequency used in chi-square calculations may be helpful.

New Contributor
Posts: 2

Re: How to create an output including row & total percentages from a 2 by 2 frequency table &amp

Thank you ballardw. I tried the OUT= option on the TABLES statement with OUTPCT, but it only gives me the row and column percentages, but not the total percentages.  For example, I would like to have the compliance rates (row percentages) of non_white (90.24%) and white (76.47%), and the total compliance rate (84%) according to the table below.

 

My question number 1 will be: how can I get the total percent (84%) as well?

 pic1.PNG

Question number 2 is: in order to put values in the format below, is there a pivot function in proc sql that allows me to transpose data?  

 

MEASURE_IDN_PCHI_P_PCHINON_WHITE_PCT_ROWWHITE_PCT_ROWTOTAL _PCT_ROW
2750.6985780.40326191   
Solution
‎10-13-2016 11:30 AM
Super User
Posts: 9,671

Re: How to create an output including row & total percentages from a 2 by 2 frequency table &amp

Can you post your data and the output.

I think you can use SQL to get that row_pct , after using proc freq to get that Chisquare,

you can combine them together into one table.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 215 views
  • 2 likes
  • 3 in conversation