I've had memberships to both places over the years. We got a Costco card as soon as they opened in West Des Moines, but found that the trip was just too far from Ames to make it worth going down there as infrequently as we did. We now go to Sam's since it's right here in town.
I confess that I still prefer Costco. The quality seemed to be a bit better and it was sure hard to beat the in-house bakery that made all those awesome pies, cakes, muffins (those led to the feeding frenzies at work when I'd bring them in), etc. Sam's probably has a better frozen selection, but still not much that I actually want to buy. I don't look at electronics stuff there since I don't buy much of that, so I don't know if any of it is a good deal or not.
Like someone just said, you don't buy everything at these places. That's just a lack of planning to buy perishables in bulk, and then not use (or freeze, if possible) them. We only buy what we can use all at once (for a holiday or get-together), what can easily be tossed in the freezer downstairs, or what will keep indefinitely in cans or a box if not opened. Many things are not worth purchasing there, but if you're smart at planning, many things certainly are.
Whatever place is closest to you is probably the better option. Neither is really worth traveling a long distance to shop, considering the cost of gas.