Welcome! You might want to subscribe to my blog: every Monday is a "Getting Started" post for people that are new to SAS/IML.
To see previous posts, go to http://blogs.sas.com/content/iml and click on the Getting Started tag in the right hand sidebar.
In order to write efficient programs, you want to avoid loops over elements of matrices. It takes time to learn how to deal with matrices as a "whole entity," so feel free to ask questions at this forum whenever you find yourself looping over all elements of a matrix.
One way to answer your question is to ese the LOC function to find the elements that satisfy the condition. Examples similar to yours are at
http://blogs.sas.com/content/iml/2011/05/16/finding-data-that-satisfy-a-criterion/
A second way is to use the CHOOSE function. See http://blogs.sas.com/content/iml/2011/08/15/complex-assignment-statements-choose-wisely/
The LOC method is more general. I think the CHOOSE function is what you need for this particular example: x = choose(x>2, 1, 0);
Rick