BookmarkSubscribeRSS Feed
deleted_user
Not applicable
hi

im still kind of new to sas and i need to count the number of times that a variable in a dataset is not null. I guess my problem is how to get it set up in a loop to print the final number.

ex. there is a dataset and the dataset has a variable that has repeating values in the column. I need to find out how many of the repeated values recieved did not have a null value.

obs date variable value
1 b g h
2 b g
3 b g k
4 b g
5 b g p

ex. like for this the variable "g" has 3 recieved that did not have null values. if this make any sense. I see what I need to do in my mind but I cannot get it to work.

Thanks,
TDS
6 REPLIES 6
deleted_user
Not applicable
First of all variables are columns and observations are rows. Having a variable called variable is just going to lead to all sorts of confusion. As it has with me. I'm not really sure what you are looking for.
deleted_user
Not applicable
I didnt name the variable "variable" i was just using that as an example. The bold variable, is the column that I am tryin to capture a specific value. The "value" column, is the column i want to determine if it is not null. That is why I had those two columns bold. I hope this helped a little. Sorry for the confusion.
deleted_user
Not applicable
Sorry, I still honestly can't figure out what you mean. I would take a guess that you might be after something like:

data output_dataset;
set input_dataset;
if value ne '' then count_non_missing+1;
run;
deleted_user
Not applicable
Thank you! that is close to what I mean...Once again sorry for the confusion.
Cynthia_sas
Diamond | Level 26
You might also investigate PROC MEANS using the N and NMISS statistics (assuming that "value" is numeric).

cynthia
Flip
Fluorite | Level 6
OK assuming that what you are asking is that you have a variable G with values:
'h'
' '
'k'
' '
'p'

In a data step you could have: if G = " " then gmisscnt +1;

In SQL you could use: count(*) where g = "" as gmisscnt

to give you a variable gmisscnt with a value = to the number of missing values.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1635 views
  • 0 likes
  • 3 in conversation