I was wondering if it's possible to create a macro variable with the same name for different BY groups? And be able to call the macro with the BY groups?
data:
| group | siteid | counts |
| 1 | MX004 | 22 |
| 2 | MX004 | 15 |
| 3 | MX004 | 37 |
| 1 | MX005 | 106 |
| 2 | MX005 | 48 |
| 3 | MX005 | 154 |
| 1 | MX006 | 108 |
| 2 | MX006 | 56 |
| 3 | MX006 | 164 |
| 1 | MX007 | 18 |
| 2 | MX007 | 10 |
| 3 | MX007 | 28 |
| 1 | MX008 | 49 |
| 2 | MX008 | 28 |
| 3 | MX008 | 77 |
want:
1. macro variable called "group1" of group=1 counts by siteid
2. macro variable called "group2" of group=2 counts by siteid
3. macro variable called "group3" of group=3 counts by siteid
Data, such as counts, belongs in a data set variable, not a macro variable. There is no concept of a BY group in a macro variable, which as we have pointed out, are simply text strings. SAS has put a great deal of effort into allowing DATA steps and PROCs to have BY group processing; if you want to do BY group processing, you should be using DATA steps and PROCs, not macro variables.
Can you explain what your goal is here, what analysis or report are you trying to perform?
@HitmonTran wrote:
I was wondering if it's possible to create a macro variable with the same name for different BY groups? And be able to call the macro with the BY groups?
data:
group siteid counts 1 MX004 22 2 MX004 15 3 MX004 37 1 MX005 106 2 MX005 48 3 MX005 154 1 MX006 108 2 MX006 56 3 MX006 164 1 MX007 18 2 MX007 10 3 MX007 28 1 MX008 49 2 MX008 28 3 MX008 77
want:
1. macro variable called "group1" of group=1 counts by siteid
2. macro variable called "group2" of group=2 counts by siteid
3. macro variable called "group3" of group=3 counts by siteid
Remembering that macro variables are always text, show us exactly what your "group1" variable is supposed to look like given that example data.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.