0

I want to use proc tabulate to display the proportions/ total count of some variables conditioned on their values - if I only want to access one variable at once I was able to achieve this by setting a specific format (please check the MWE). However, if I want to access two variables at once (like score_1 >= x OR score_2 >=y) I get nowhere.

MWE:

data have;
input score_1 score_2;
datalines;
2 7
4 4
7 2
;

proc format;
value cut_fmt 
    low - 2 = 'non-critical'
    3 - high = 'critical'
    ;
run;

proc tabulate data = have missing;
format score_1 score_2 cut_fmt.;
class score_1 score_2; 
keylabel N = ' ' ColPCTN = '%' all = 'Total'; 
table score_1 * N score_2 * N, all;
run;

output

I now would like to have an extra row where it says:

score_1 OR score_2   
non-critical         0
critical             3

Is there a way to achieve this in proc tabulate (this shouldn't be possible with a format statement I guess) or would I need to create a new variable before and just use this one then?

1 Answer 1

1

Create a new variable and add it to the table statement. You will also need classdata to ensure 0 counts are presented.

Example:

data have;
  input score_1 score_2;
  worst_case = max(score_1, score_2);
  label worst_case = 'score_1 or score_2';
datalines;
2 7
4 4
7 2
;

proc format;
  value cut_fmt 
    low - 2 = 'non-critical'
    3 - high = 'critical'
    ;

data combinations;
  score_1 = 2; 
  score_2 = 2; 
  worst_case = 2; output;
  score_1 = 3; 
  score_2 = 3; 
  worst_case = 3; output;
run;

options missing='0';

proc tabulate data = have classdata=combinations;
  class score_1 score_2 worst_case;
  format score_1 score_2 worst_case cut_fmt.;

  keylabel N = ' ' ColPCTN = '%' all = 'Total'; 

  table score_1 score_2 worst_case, all;
run;

options missing='.';
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I almost thought so. BTW, nice idea with the classdata approach. I was trying a different angle with preloadfmt missing options to the class statement and printmiss misstext='0' to the table statement which yields the same. Will definitely look into your approach!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.