You would be better off transposing your data then you don't have this issue. If your data is organized as ID Procedure Procedure_Date Procedure_Count 1 6701 01Jan2018 1 2 4533 03Jan2018 1 1 6701 01Jan2017 1 ... Then you could do: data want; set have; where procedure in (6701); run; In general, this structure is more useful for answering a variety of questions. I worked with healthcare data for over 5 years and have found this data structure to be optimal. Here's a tutorial on transforming your data: https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/
... View more