Schwa
Schwa

Reputation: 139

Missing values in a FREQ (SAS)

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?

Upvotes: 2

Views: 964

Answers (1)

Reeza
Reeza

Reputation: 21294

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.

Upvotes: 1

Related Questions