Species distribution models (SDMs) correlate species occurrences with environmental conditions and underpin much of ecological research. A key consideration in developing SDMs is selecting the optimal set of environmental predictor variables, which vary depending on the specific application and species involved. Existing SDMs approaches are limited to a fixed set of predictors defined a priori. This becomes problematic whenever predictors are suboptimal for a particular species or research question to be answered, or when some predictors are unavailable at a given location. To address this, we introduce MaskSDM, a versatile approach that allows end-users to choose relevant variables and gain insights into their contributions to predictions. Our approach employs masked data modeling to learn robust data representations. This allows MaskSDM to effectively handle missing data during both training and inference, addressing a common challenge in real-world geospatial datasets. Evaluations against alternative methods demonstrate that MaskSDM offers improved predictive performance and facilitates valuable analyses of variable contributions.