Factor out variable prep from Dataset#write.