In general, yes you can check your bag through; just make sure to let the SFO checkin agent know about your other itinerary before your bag is tagged to ORD and disappears down the belt.
The only exception is if your other flight is on a different airline AND it's a carrier with which UA has no interline baggage agreement. (Major legacy carriers are fine; a charter operator or a niche carrier like JetBlue might not be).