Help using Base SAS procedures

simple loop procedure

Reply
N/A
Posts: 0

simple loop procedure

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
N/A
Posts: 0

Re: simple loop procedure

Posted in reply to deleted_user
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.
N/A
Posts: 0

Re: simple loop procedure

Posted in reply to deleted_user
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.
N/A
Posts: 0

Re: simple loop procedure

Posted in reply to deleted_user
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;
N/A
Posts: 0

Re: simple loop procedure

Posted in reply to deleted_user
Thank you! that is close to what I mean...Once again sorry for the confusion.
SAS Super FREQ
Posts: 8,868

Re: simple loop procedure

Posted in reply to deleted_user
You might also investigate PROC MEANS using the N and NMISS statistics (assuming that "value" is numeric).

cynthia
Super Contributor
Posts: 359

Re: simple loop procedure

Posted in reply to deleted_user
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.
Ask a Question
Discussion stats
  • 6 replies
  • 131 views
  • 0 likes
  • 3 in conversation