Barite | Level 11

## To treat missing values with zeros

Hello all,

I wrote a loop that goes through variables to replace dot (a missing value) with zero; Now I want to add another loop to go through observations as well.

This is my code and your help is greatly appreciated. Blue Blue

`Data simpleData;Input Var1 Var2 Var4 Var5 Var6 Var7 Var8 ;cards;5 7 3 6 5 8 34 7 3 6 5 8 33 6 3 3 5 8 35 4 3 . 3 8 35 4 3 3 3 8 35 . 3 3 3 8 35 7 3 3 3 8 15 7 3 3 3 8 0run;data mathtop;set simpleData;varResult = var1 * var2;Array varArr(7)  Var1 Var2 Var4 Var5 Var6 Var7 Var8;Do i = 1 to 7;if varArr(i)=. Then varArr(i)=0;var9 = var4 + var8;end;Run;`

Blue Blue
1 ACCEPTED SOLUTION

Accepted Solutions
PROC Star

## Re: To treat missing values with zeros

You don't need a loop to process observations as SAS automatically will process all rows one after the other.

View your MATHTOP dataset to prove this program is already working correctly.

4 REPLIES 4
PROC Star

## Re: To treat missing values with zeros

You don't need a loop to process observations as SAS automatically will process all rows one after the other.

View your MATHTOP dataset to prove this program is already working correctly.

Opal | Level 21

## Re: To treat missing values with zeros

Besides of a do loop you could also use Proc Stdize as proposed in the solution here

Diamond | Level 26

## Re: To treat missing values with zeros

I hope you have a really really really good reason why you want to replace missings with zeros, as there are plenty of situations where this is not a good idea (and a few situations where this makes sense). A word to the wise...

--
Paige Miller
PROC Star

## Re: To treat missing values with zeros

One example of a program that doesn't need to replace missing values with zero is the one you posted. You can get the same result by replacing everything from the array statement to the end with:

var9 = sum(0, var4, var8);
Discussion stats
• 4 replies
• 1119 views
• 4 likes
• 5 in conversation