简体   繁体   中英

2x2 table with frequency and overall percentage in SAS - proc tabulate?

I have a set of pre and post scores, with values that can be 1 or 2, eg:
Pre Post
1 2
1 1
2 2
2 1
1 2
2 1
etc.

I need to create a 2x2 table that lists the frequencies, with percentages ONLY in the total row/column:

           1           2       Total
1         14          60      74 / 30%
2         38          12      50 / 20%
Total   52 / 21%    72 / 29%    248

It doesn't need to be formatted specifically with the / between the n and percent, they can be on different lines. I just need to make sure the total percentages (no cumulative percentages) are in the table.

I think that I should use proc tabulate to get this, but I'm new to SAS and haven't been able to figure it out. Any help would be greatly appreciated.

Code I've tried:

proc tabulate data=.bilirubin order=data; 
   class pre ; 
   var post ; 
   table pre , post*( n colpctsum); 
run;

You could make your own report. For example you could use PROC SUMMARY to get frequencies. Add a data step to calculate the percent and generate a character variable with the text you want to display. Then use PROC REPORT to display it.

proc summary data=have ;
  class pre post ;
  output out=summary ;
run;
proc format ;
  value total .='Total (%)';
run;
data results ;
  set summary ;
  length display $20 ;
  if _type_=0 then n=_freq_;
  retain n;
  if _type_ in (0,3) then display = put(_freq_,comma9.);
  else display = catx(' ',put(_freq_,comma9.),cats('(',put(_freq_/n,percent8.2),')'));
run;
proc report  missing data=results ;
  column pre display,post n ;
  define pre / group ;
  define post / across ;
  define n / noprint ;
  define display / display ' ';
  format pre post total.;
run; 

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM