I've been playing the flute for over a year. I have multiple music books from different stores and different editions, and I've noticed that 99% of the music written for flute has a few flats in the key signature. Recently, I've started playing the saxophone, and most of the music is sharped. Why is this so? Can it have anything to do with the saxophone being a transposing instrument?
In most cases, it's a byproduct of the given instrument's construction.
For example, the four open strings of the violin (with standard tuning) are:
You'll notice that each of these pitches is the tonic of a key with sharps in its major key signature. As such, a violinist (and a violin section) will sound fuller when playing in keys that use these open strings. D♭ major, meanwhile, doesn't use a single one of these open strings.
Similarly, let's look at a B♭ trumpet with three valves. Here are the concert pitches (within two octaves) that a trumpet can play without using any valves:
In order to play the other pitches, the trumpeter needs to introduce various valve combinations, which introduces a host of other problems. For instance, these valve combinations extend the length of tubing that the air must go through within the instrument, making these pitches harder to tune, harder to articulate cleanly, and harder to create a wide dynamic range. There's also the issue of finger dexterity; a trumpet playing in B major is using many more (and more difficult) finger combinations than one playing in B♭ major.
Of course, professional musicians are expected to play in any given key at any time just as well as they'd be expected to play in one of these "easy" keys for their instrument.
You mentioned the notion of transposing instruments. An alto saxophone, for instance, plays pretty easily in concert B♭ major. But this two-flat key signature, when written for the saxophone, is actually written with one sharp (G major)! So the effect of transposing instruments isn't really that large; if anything it's a little bit misleading!
In theory, transposing notation has no influence. Yes, an A clarinet requires three more flats to notate than non-transposing instruments for the same key, but at the end of the range of keys things reverse themselves: where normal instruments notate six flats to indicate G flat major, an A clarinet would simply switch to notate in A major (rather than double flat B major) and use three sharps rather than nine flats.
However, in practice the remote keys are rare, so the player of a down-transposing instrument probably does see a lot more flat marks than a string instrument would.
A further influence is the ease of playing in different scales. In an orchestra you have to play the key that the composer chose for all players, but in solo compositions, if one scale is easier to play than another, composers will probably chose the corresponding key more often for their compositions in the first place. These two influences overlap to varying degrees in different instruments (I'm not sure which way the saxophone goes, since there are many different sizes with many different preferred keys).
Whenever I listen to concert band music, I find that the sound majority of Grade 0.5-1.5 pieces are in B flat major. Flutes read this as B flat major (since they're non-transposing instruments), while alto saxophones read this as G major.
This might not explain why solo repertoire for flutes and saxes stick to flatter/sharper keys, respectively, but it sure explains why group repertoire for both instruments stick to flatter/sharper keys.
I also find an awful lot of relatively easy concert band repertoire in E flat major (C major for alto sax), which just confirms the flat/sharp skew.
As Kilian says, in a sense, it makes no difference. Let's suppose that we arrange Bach's Well-Tempered Clavier for a variety of instruments. Every instrument, transposing or not, will play in all 12 major and 12 minor keys. (Assuming that we use enharmonic equivalents and the alto sax does not have to play in A# major with 10 sharps).
However, leaving aside the Well-Tempered Clavier, and a few other similar suites which are mostly for the piano, music in 5, 6, or 7 sharps or flats is fairly rare.
If we suppose that most music uses at most 2, 3, or 4 sharps then the Bb clarinet will mostly have lots of sharps in its key signature and an Eb clarinet or sax will have even more. I know this from personal experience as a player of both.
Despite being used to transposing instruments, I don't like the system. There is an obvious attraction for a family of related instruments such as the saxophone but the recorder manages without that. It seems strange to play in the treble clef on the baritone saxophone and get notes that belong in the bass clef.
Some instruments are intrinsically easier to play in certain keys.
On the flute, all keys are equally easy or difficult, and with the instrument's range, it makes very little difference what key you play in. In beginner music, the key will be near C in the circle of fifths or will be whatever is easiest for the instruments the flute is playing with.
On the violin and other strings, keys that allow more open strings to be used are more popular. Between a cello, a violin, and a viola, the open strings are C, G, D, A, and E. A guitar has A, D, G, B, and E. Open strings make the music easier for a beginner to play, and for a more advanced player, gives the option of choosing whether they want the sound of an open string, or would prefer the sound of a fingered note. It's a significantly different sound. So classical string music in D or A seem to be most popular, with C, G, and E also showing up a lot. Other keys show up less often. If a school has a string orchestra, they probably play lots of music in D instead of Bb.
In a school band, it's the brass section that determines the key usually used. The Bb trumpet is the usual student instrument, and it is most easily played in the key of Bb. The further you get from the key of Bb (going around the circle of fifths), the harder it is to play. French horns are also Bb instruments, as is the tenor trombone, which is what students usually play. Brass instruments can be bought for different keys, or a skilled player can play them as chromatically as a piano. But at a beginning level, the brass is unlikely to either own multiple instruments or be skilled enough to play well in challenging keys.
There's one easy answer that explains certain instruments: On strings, it's generally easier to go higher, hence a fondness for sharps - in general you always can move down a given string, but if you're going to a lower note you may have to jump to a different string.
On brass, it's generally easier to go lower, hence a fondness for flats - in general you can just add a valve to what's being played, but going higher may have slightly trickier "valve math"