How do they know if something causes cancer?

Do they do it only by surveys (which is what it seems like)? Or do they have other ways of finding out?

They do surveys, but they also feed things to animals to look for cancers, or inject them, implant them, whatever.
IIRC there’s a basic presumption that the greater the dose, the liklier the cancer - and there’s no nonzero dose that doesn’t cause some incidence of cancer. What they’re looking for is how steep the curve is, i.e. the effectiveness of the carcinogen.
There’s also a theoretical side that looks for known carcinogeneticity of chemically similar substances.

Both ways.
Sometimes there’s a huge amount of people exposed or a moderate amount of people exposed at high doses, so it’s easy to see how much the people exposed got cancer compared to people who weren’t exposed, then do simple statistics and be sure that the substance causes cancer (for instance cigarettes, asbestos, radioactivity such as the case of radium watch painters).

Another way to find out is to test the substance on rats and other animals, presuming the effect is similar for rats and humans. The best way to do this is to test with the kind of lowish doses that people are actually exposed to. However at the lowish doses, only a few of the rats get cancer, so you need a lot of rats (expensive) and a long time.
So what they usually do is use fewer rats, but higher doses, assuming that ten times the dose gives ten times the chance of getting cancer. This isn’t a completely ridiculous assumption, given what we know about how carcinogens work, but is still a bit of an assumption.

The final way to find out about whether a substance is a carcinogen is to compare it to similar substances. If it’s very similar to known carcinogens, it’s probably carcinogenic to some degree, too (and vice versa if everything similar to it is considered non-carcinogenic, then it’s probably OK, too).
You can be as complex as you want in deciding what is similar, starting with a quick look at chemical structures and saying ‘gee, they look similar’, or as complex as figuring out exactly how certain carcinogens cause problems and seeing if the chemically important parts of those carcinogens are present in the substance you’re wondering about.

In real life, all three ways are used, in combination. There aren’t a whole lot of good human studies (and the whole point is to keep it that way!). Extensive animal tests are usually only done when there’s a good reason to be concerned about a substance, but there are enough to be fairly sure about that some chemicals are dangerous. And making guesses bases on chemical structure gives some good ideas about which chemicals to be cautious with, or ones that might be worth doing animal tests on. But still there are a lot of ‘suspected’ or ‘likely’ human carcinogens.