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

Showing results for

- Home
- /
- Programming
- /
- SAS Procedures
- /
- With proc freq can you only print the counts for a certain value of a ...

- 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 02-27-2020 06:58 PM
(718 views)

Hello,

With proc freq (or another proc), is there a way to only print the counts for a certain value of a variable? I have 30+ variables and for each of those variables, I want to know how many observations in my sample had a value of 0.

Thanks!

Laura

1 REPLY 1

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

One basic approach to count a specific value for a variable with Proc Freq;

proc freq data=sashelp.class; where sex='F'; tables sex; run;

Which would require 30 calls to proc freq.

If there are not many potential values involved for any of the variables (less than 10 values) I would likely just dump them all into a single proc freq call an look.

Or perhaps something like:

data need; set have; array v <list of your thirty variables>; do i= 1 to dim(v); variable = vname(v[i]); if v[i]=0 then output; end; keep variable; run; proc freq data=need; tables variable; run;

The count of variable is how many times it appeared as a 0 in the source data set. Note: if you have a mix of character and numeric variables this won't work as an array can only have variables of one type. So if you actually have some character "0" you would split the variables between two differently named arrays and the character comparison would be for "0" instead.

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.