Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count number of 0 values

Tags:

sas

Similar to here, I can count the number of missing observations:

data dataset;
  input a b c;
cards;
1 2 3
0 1 0
0 0 0
7 6 .
. 3 0
0 0 .
;
run;

proc means data=dataset NMISS N;
run;

But how can I also count the number of observations that are 0?

like image 841
bill999 Avatar asked Jan 18 '26 06:01

bill999


1 Answers

If you want to count the number of observations that are 0, you'd want to use proc tabulate or proc freq, and do a frequency count.

If you have a lot of values and you just want "0/not 0", that's easy to do with a format.

data have;
  input a b c;
cards;
1 2 3
0 1 0
0 0 0
7 6 .
. 3 0
0 0 .
;
run;

proc format;
  value zerof
  0='Zero'
  .='Missing'
  other='Not Zero';
quit;

proc freq data=have;
  format _numeric_ zerof.;
  tables _numeric_/missing;
run;

Something along those lines. Obviously be careful about _numeric_ as that's all numeric variables and could get messy quickly if you have a lot of them...

like image 131
Joe Avatar answered Jan 19 '26 18:01

Joe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!