DRY variable setting across templates (macro for variable?)
As you noted in your comment, the Twig Perversion plugin will do exactly what you need. It allows you to return a value from a macro, which isn't typically something that Twig permits.
Personally, I'd consider it to be fairly safe to rely on this plugin for a few reasons. Marion is a long-standing and trusted developer in the community, the plugin is relatively simple, and could easily be replaced with a small custom module if it ever went defunct. It also doesn't touch your data, so removing it in the future won't cause any problems.