Set different Canonical url programmatically for every post

You can do that programmatically right from inside the plugin’s settings by using the wpseo_canonical filter.

You can also set it on a per post basis:

Yoast Canonical links settings

You can even set the canonical links for categories, tags and any taxonomy for that matter as well.
All you have to do is follow instructions at Canonical URLs in Yoast SEO