It would be a good idea to show us what you've tried so far along with some sample data - people on here are very helpful but they like to see you've actually made an attempt first
Firstly that's not a macro
Secondly how are you ensuring only unique values are selected?
Thirdly hopw are you ensuring correct mayching by id?
Fourthly where are your parameters?
If you don't have sample data then create some, run your program to see what happens.......
Itemize your requirements.
Break it into steps first.
Then get it working for a non macro situation.
Then convert it into a macro.
Your current attempt is missing several of the criteria in the question .
i won't do your homework but happy to help debug.
Macro programming involves determining what you need to do without any macro coding. Then adding the parameters to make the macro more "dynamic" or flexible than the fixed code for one case.
If you don't know how to do the case without a macro then starting with a macro is likely to end in a failure as the macro language basically is intended to write code to perform the process. So if you had the base code that would do one case we could show you where to make the changes suitable for a macro to process different data sets and variables.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.