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 3
4 7 3 6 5 8 3
3 6 3 3 5 8 3
5 4 3 . 3 8 3
5 4 3 3 3 8 3
5 . 3 3 3 8 3
5 7 3 3 3 8 1
5 7 3 3 3 8 0
run;
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;
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.
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.
Besides of a do loop you could also use Proc Stdize as proposed in the solution here.
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...
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.