Roger Federer had a fourth set to remember as he saved seven match points against Tennys Sandgren at the Australian Open.