It is pretty hard to prevent spam in any form. Depending on its type, it may be theoretically possible (like in the cases of phone and SMS spam) and likely impossible. You can protect your social networks by restricting tagging you and unfollowing the hashtags that are often getting spammed. Another way to slowly-but-steadily decrease the amount of spam is to report the accounts that spread it. For all other kinds of spam, it is easier to ignore & avoid touching them.