Hello @MattFD I do not have a conceptual understanding of your business case. However if one looks at the first Proc SQL code that creates the dataset controls_UID, the step creates a cartesian join and keeping records where there is a match in sex and the age in cases between the age limits of the table controls2. This I feel is the cause of the issue you are facing. Review the logic of this step in line with your business requirements.
... View more