turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- simple loop procedure

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-16-2009 09:55 AM

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

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-16-2009 10:13 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-16-2009 10:26 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-16-2009 10:33 AM

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;

data output_dataset;

set input_dataset;

if value ne '' then count_non_missing+1;

run;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-16-2009 10:42 AM

Thank you! that is close to what I mean...Once again sorry for the confusion.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-16-2009 11:57 AM

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

cynthia

cynthia

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-16-2009 10:41 AM

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.

'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.