BookmarkSubscribeRSS Feed
Calcite | Level 5



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.




Super User

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

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

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;
   keep variable;

proc freq data=need;
   tables variable;

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.




Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.


Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 


Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 1 like
  • 2 in conversation