Calcite | Level 5

## Counting non blanks for a single column

Hello all,

I'm working on a project where I need to count the total responses for each variable. The variables represent responses to different survey questions and I just neet to know how many people responded to each questoin. The total number of responses for each question will then be used as the numerator with the total number of observations as the denominator. Is there a shortcut to doing this? I have over 300 variables and 180,000 observatioins, I would rather not have to hard code all of this.

2 REPLIES 2
PROC Star

## Re: Counting non blanks for a single column

Well, you haven't been specific about what form the output should take.  Here's a reasonable and easy way:

proc summary data=have;

var _numeric_;

output out=want (drop=_type_ _freq_) n=;

run;

It gives you one observation, where the value of each numeric variable is the number of non-missing values from the original data set.  Perhaps that is just right, or perhaps you can use it as a starting point to clarify what you would like the results to look like.

Super User

## Re: Counting non blanks for a single column

@pbstubejunkie wrote:

Hello all,

The total number of responses for each question will then be used as the numerator with the total number of observations as the denominator.

That looks a lot like a percentage. You haven't stated whether you need the result in a dataset or a report.

Proc freq will do that percent calculation:

```proc freq data=have ;
tables _character_ _numeric_/missing nocum;
run;```

The tables statement says to use all the character and numeric variables. Missing says to include the missing/blank values as a category so you will get percentages based on all records when calculating the percent for each response. The nocum suppresses a cumulative percentage output. The tables statement is needed because otherwise Proc Freq will exclude the missing values from denominator.

If you need a data set you could add and ods output statement

```proc freq data=have ;
tables _character_ _numeric_/missing nocum;
ods output onewayfreqs=work.freqs;
run;```

though that may take some massaging for some other uses because you will have columns for the variable values and the formatted values as columns along with the count and percentages and a column to indicate which "table", or variable was summarized.

Discussion stats
• 2 replies
• 2138 views
• 0 likes
• 3 in conversation