2
votes

I'm going to ask this with an example...

Suppose i have a data set where each observation represents a person. Two of the variables are AGE and HASADOG (and say this has values 1 for yes and 2 for no.) Is there a way to run a PROC FREQ (by AGE*HASADOG) that forces SAS to include in the report a line for instances where the count is zero?

By this I mean: if there is a particular value for AGE such that no observation with this AGE value has a 1 in the HASADOG variable, the report will still include a row for this combination (with a row percent of 0.)

Is this possible?

1
Use the SPARSE option, but please don't ask what's possible, ask how to do something instead.Reeza
I'm new at SAS; I don't actually know what's possible yet. :)Schwa

1 Answers

1
votes

The SPARSE option in PROC FREQ is likely all you need.

proc freq data=sashelp.class;
  table sex*age / sparse list;
run;

If the value is nowhere in your data set at all, then there's no way for SAS to know it exists. In this case you'd need a more complex solution, basically a way to tell SAS all values you would be using ahead of time. This can be done via a PRELOADFMT or CLASSDATA option on several procs. There are asked an answered questions on this topic here on SO, so I won't provide a solution for this option, which seems beyond the scope of your question.