I suggest to add a new comparison mode [tt]12[/tt] to ditto to make this job simple and consistent with the possibilities of comparison type [tt]1[/tt].
Mode [tt]12[/tt] would check if a given key exists. That only makes sense for template variables as they don’t exist for every document but only for those to which template they’re associated. A use case would be to filter for multilingual vs. monolingual documents managed by YAMS as all the multilingual documents come with TVs like [tt]pagetitle_(yams_id)[/tt]:
[!Ditto? &language=`(yams_mname)` &parents=`1` &tpl=`UrlsetURL` &depth=`5` &dateSource=`editedon`
&dateFormat=`%Y-%m-%d` &display=`all` &showInMenuOnly=`0` &seeThroughUnpub=`1`
&filter=`type,reference,2|searchable,1,1|pagetitle_(yams_id),,12`!]
This would give me a list of the monolingual documents using template [tt]UrlsetURL[/tt].
Find the hacked file attached, feel free to use and if it makes sense feel free to include in some future ditto release.