It's a pretty old adage...but what does it mean?
The quote is attributed to Mark Twain, and if we take him at his word, he did, essentially, write what he knew firsthand. Twain is famous for writing about a world he was familiar with, generally times and places he'd experienced (though not always--I doubt he'd been to King Arthur's Court any more often than the Connecticut Yankee had, but you never know). Still, we as writers clearly branch out and write what we don't know pretty often, too--for every writer inspired by his or her hometown, there's another writing about space colonies on asteroids or court intrigue in 16th century France.
So, can you effectively write what you don't know?
I'm going to say no and ask that you hold your horses to let me explain. A writer can't write what he or she has no grasp on--but there are more ways that living through it to get a handle on a subject. After all, writers write dozens of lives but only live one. And fiction isn't memoir.
I think there are two ways to get at what you need to know to write what you haven't experienced.
Secondhand and Transferable Knowledge Also called "research." You don't need to live through the Black Death to know what the symptoms are, or work for NASA to get a working knowledge of a shuttle launch. This is what libraries, the internet, and experts are for.
There's also the stuff you already know--or the stuff you didn't know you knew. No, you've never crawled across a desert nearly dying of thirst. But you've been hot and exhausted and desperate for a Gatorade, right? (If not, see the next section.) Take the tactile and emotional elements of what you remember from that experience--the sweat tickling your back, the sun feeling like a blanket smothering you, the anxiety rising in your chest as you started to question--really question--if you were going to be ok.
Putting on Their Shoes In the movie Tropic Thunder, the catalyst for the film's action is that a director decides that his namby-pamby actors can't capture the fear, courage, and grit that was the Vietnam War unless they're put "in the sh!t" and forced to survive in the jungle for a while. Sometimes namby-pamby writers can't capture the physical reality or emotional depth that accompanies what they want to write about unless they get closer to it. I don't suggest getting dropped in the jungles of Southeast Asia, but you do have some options.
You might have an experience that can transfer--you've put on similar shoes and know how to walk in them. Other times, you might need to find a way to put on those shoes to get yourself to a place where you can write what you know.
If you just have no clue about the tangibles--what does riding a horse actually feel like? How loud is a gun when it's fired?--you can find out. Do some firsthand research--find a situation as close to the one you want to write about and see if you can experience it (safely). If you're trying to write a story about a military campaign and have never even camped, this might be a good time to see what it feels like to sleep outside. If you're writing a historical ball scene but have never danced, you might want to seek out a way to experience that.
If you're at a loss about an emotional experience, you have two choices. Go back and ask yourself if you do have any transferable knowledge--perhaps you haven't lost a spouse, but you can channel what grieving feels like from others losses. But if you really have nothing to pull from, I'm going to suggest something radical--maybe you aren't ready to write that particular story yet. There's a reason that writers can have lifelong careers and often get better as they get older--when you experience more, you have more to write from. We've all read attempts at capturing an emotional moment that fall flat--it's probably because the writer wasn't ready to tackle that subject yet.
What do you think? Do you need to write what you know--or know what you write? Or can a good writer create a fictional experience without personal experience to pull from?