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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.