BookmarkSubscribeRSS Feed
HitmonTran
Pyrite | Level 9

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:

groupsiteidcounts
1MX004  22
2MX004 15
3MX004  37
1MX005  106
2MX005  48
3MX005  154
1MX006  108
2MX006  56
3MX006  164
1MX007  18
2MX007 10
3MX007 28
1MX008  49
2MX008  28
3MX008  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

 

 

 

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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?

--
Paige Miller
HitmonTran
Pyrite | Level 9
it goes back to my previous issue using proc report by statement, and
calling the macro in the define statement
PaigeMiller
Diamond | Level 26
Explain. I'm pretty sure a non-macro solution is available and easier, but until I know what you are trying to do, I can't help further.
--
Paige Miller
ballardw
Super User

@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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 838 views
  • 0 likes
  • 3 in conversation