At the end of the Sui dynasty, when the state was engulfed in uprisings against Emperor Wen's son Emperor Yang, Yang Shidao was at the eastern capital Luoyang, and was subsequently detained by the general Wang Shichong, who deposed Sui's final emperor Yang Tong (Emperor Yang's grandson) in 619 and established a new state of Zheng as its emperor, but Yang Shidao was eventually able to go to Chang'an, where another general, Li Yuan had established the Tang dynasty as its Emperor Gaozu in 618. (It is not completely clear whether Yang's travel to Chang'an was before or after Zheng's fall to Tang in 621, but likely before.) Late in 621, when Eastern Tujue forces attacked Ling Prefecture (靈州, roughly modern Yinchuan, Ningxia), Yang Shidao was referred to as the commandant at Ling Prefecture, and he was able to repel the Eastern Tujue attack; he would again be involved in a campaign resisting Eastern Tujue attacks in 622.
As the Sui dynasty came to an end, with Emperor Wen's son Emperor Yang facing rebellions, Yang Shidao was stationed at Luoyang, where he was later detained by General Wang Shichong. Wang then overthrew the last Sui emperor, Yang Tong, and established a new state of Zheng in 619. However, Yang Shidao eventually made his way to Chang'an, where Li Yuan had established the Tang dynasty as Emperor Gaozu in 618. The timing of Yang's trip to Chang'an is unclear, but it likely occurred before Zheng's defeat by the Tang in 621.