Help using Base SAS procedures

Reporting summarised data with Proc Tabulate

Regular Contributor
Posts: 151

Reporting summarised data with Proc Tabulate

I often find that I'm drawing on the formatting features of Proc Tabulate to neatly present data which have already been summarised. That is, I just want to report single values in the table cells rather than summary statistics like the mean. I can, of course, do this by just presenting the mean (or the min, or the max etc) of the value. However, I would like to be able to double-check that I do indeed only have one value in the cell. Any suggestions on how to do this?

More concretely, consider the following program which tabulates average income by sex and age. The first table works fine as a way to present these data. I'm using 'min' not because I want the minimum, but simply to report the (single) cell value. In the second table, I've introduced a mistake. I'm only tabulating by age, but there are two records in every cell in this case.

What I would like would be some way to flag that the second table is not valid for my data. A crude way is to tabulate the N function for each cell and check this for all 1 s - but this produces an additional ugly table.

Ideally I would like to do with an 'only' function. This would return a missing value if the values in the cell had a positive variance (or range), and would return the mean (or min or max) if the variance was zero. I don't think this is possible in SAS.

Any other suggestions? Or should I use some totally different approach to tabulating already summarised data. Proc report is naturally oriented towards listing cases, but my understanding is that it doesn't have the flexibility of tabulate for rearranging row and columns.

data test;

input sex $ age $ avg_income;


M Y 100

M O 210

F Y 66

F O 33



proc tabulate data=test;

  class sex age;

  var income;

  table min=""*avg_income*sex,age;

  table min=""*avg_income*age;


Ask a Question
Discussion stats
  • 0 replies
  • 1 in conversation