Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- Programming
- /
- Re: Counting non blanks for a single column

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 09-21-2018 12:31 PM
(2148 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@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.

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. **Registration is now open through August 30th**. Visit the SAS Hackathon homepage.

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.