How to preconfigure wifi on Mac OS X (Yosemite)?
Go to the network preferences panel in System Preference
Select airport, then 'Advanced...' 
Press the plus button 


It will work even when the network isn't near.