You're confusing mass with weight. Say, somewhere in space, there's a ball, and nearby there's no other sun/planet/anything. Then that ball will experience no force and thus would appear to have no weight. but it will still have mass. Weight is a force that a mass experiences due to gravity. mass is due to atoms and molecules. If something pulls (gravitational pull) those atoms/molecules, then they will experience a force and thus they will appear to have some weight if you decide to measure that weight. If there is no gravity felt by an object, which losely put, means that there is no force from any neighboring massive body.
Remember, weight = mass x gravity. where weight is the force and gravity is the acceleration, or $F=ma$. Thus, mass is an inherent property of matter. If there is matter, it may have mass (if it's travelling at speeds << c), and it may have some weight, provided it is attracted by another object.
I gave somewhat a very simplistic explanation of how mass/matter is defined. I could go into proper details but the fact is that the term matter has no universally-agreed definition. You can find more detailed explanation here: http://en.wikipedia.org/wiki/Mass. But you need to know some physics beforehand to properly understand.