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
SAS Super FREQ
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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 6 replies
  • 665 views
  • 0 likes
  • 3 in conversation