The macro language is a code generator, so please show the code you want to create through use of the macro facility.
Hi,
What code have you tried? When we teach the SAS Macro class, we recommend starting with a working program for one example where everything is hard-coded to make sure that you have working code. What will happen if month=jan or if month=feb -- will you have your macro program type an entire program or just type one line of code. Remember that the SAS Macro Facility only generates or types code for you. So the reason to start with a working program is so you know exactly what code has to be generated for each condition.
The short answer to your question is yes-- sort of -- you can create "numbered" values as SAS macro variables, such as &month1, &month2, &month3, etc and then you can test the values of those macro variables with a %IF statement. Or, you could create a long string and process through the string with a %DO loop without creating numbered macro variables. It depends on what you want to do.
However, you have to know what happens on the "true" condition and the "false" condition. Even though the macro variables can numbered and may look like array elements, they are not technically members of an array and you do not reference them as if you had issued an ARRAY statement for regular data set variables which were members of an array. And you can use a %DO loop in SAS macro code to reference either numbered macro variables or a long string of values in an orderly fashion. Here's one example using just a long string separated by spaces, then when one of the scanned values is equal to May, type some PROC PRINT code for processing:
But it would be useful to see what code you've tried, to understand your data, to understand what your full task is and to know what the desired end result is.
Cynthia
Post the code you want to make dynamic. I won't repeat this a third time.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.