How come the Atacama is extremely dry when it is so close to the ocean? This is a challenging question to consider, especially considering the proximity to the ocean. The first consideration is that there are two mountain ranges that create a rain shadow that literally keeps rain clouds from entering this area. The second reason is that there are some winds which are called the Pacific Anticyclone that permeate the area. The third thing to keep in mind is that there is another prominent air flow called the Walker circulation which causes air to descend near the Atacama.
Since this air is extremely dry, this keeps the entire area dry. Finally, there is an ocean current, the Humboldt Current, sometimes called the Peru Current, which brings cold water northward along the coast of the continent. This cold air keeps the air dry because cold air doesn't hold much water.