I want to convert the above to a macro with the places in bold replaced by macro arguments. Is this possible? especially the second higlighted text I'm not able to get what the syntax would be with macro arguments.
These points were mentioned and offered guidance in your other active post. Your PROC SQL invocation needs to be syntactically correct if you want to generate SAS macro variables to use within a macro execution. Or a DATA step approach is possible also, as was mentioned, using the CALL SYMPUT technique to register a SAS global macro variable. Along with that, you must define your SAS macro with the macro variable (symbolic - using an ampersand) reference so that SAS will resolve them at compilation time. To execute the macro with macro variables passed, you must specify them on the %MACRO statement as (macro_var_parameters); -- within the parentheses.
Short of what's already been offered (and there may be some to do the coding for you), it's time to get the DOC out and learn about SAS MACRO language programming, one step at a time.