As has been suggested previously on this forum channel, suggest you start out first with a working SAS program to confirm the basic logic and code required (DATA, PROC steps, and within them any SAS functions needed).
Then, based on what component(s) of your code is expected to be "variable", then consider leveraging the benefits of the SAS macro facility to create an suitable process that offers desired flexibility that's needed to suit our data filtering and analysis requirements.
There are multiple approaches and SAS facilities to consider using, what with PROC SQL, PROC SORT, DATA step (using MERGE with a BY), and associated SAS functions like DAY().
Especially considering that you are not familiar with SAS macro coding (as stated in your post), it's best to define the logic/process flow, then come back to the forum for additional guidance with evolving the code-piece into a macro, as required.
Scott Barry
SBBWorks, Inc.