I wrote a general macro that does that (I use it all the time). Here is how to use it: The macro is called %metric_list and the code to define it is below. You supply all the "components" of your variable names and the macro returns a list of variables for you. In your case, the first component seems to be the "WAITCAT" prefix As the second component, you have three numbers 30, 40, and 50 for each set And finally you have multiple sets, each one with a different suffix ("A", "B", etc.) You can also specify a separator (in this case, none is needed, so we just use "sep=") Example: *Create list of variables;
%let list_of_variables = %metric_list(WAITCAT, 30 40 50, A B C D E, sep=);
*Print list;
%put list_of_variables = &list_of_variables.;
*The output that you will get is:
WAITCAT30A WAITCAT30B WAITCAT30C WAITCAT30D WAITCAT30E...
WAITCAT40A WAITCAT40B WAITCAT40C WAITCAT40D WAITCAT40E...
WAITCAT50A WAITCAT50B WAITCAT50C WAITCAT50D WAITCAT50E...
; Is that what you were expecting to get? If you meant to get only once set at a time (e.g. A, B, C, etc.) then this is another way to use it: *Create list of variables;
%let list_of_variables_A = %metric_list(WAITCAT, 30 40 50, A, sep=);
%let list_of_variables_B = %metric_list(WAITCAT, 30 40 50, B, sep=);
%let list_of_variables_C = %metric_list(WAITCAT, 30 40 50, C, sep=);
*Print list;
%put list_of_variables_A = &list_of_variables_A.;
%put list_of_variables_B = &list_of_variables_B.;
%put list_of_variables_C = &list_of_variables_C.;
*The output that you will get is:
list_of_variables_A = WAITCAT30A WAITCAT40A WAITCAT50A
list_of_variables_B = WAITCAT30B WAITCAT40B WAITCAT50B
list_of_variables_C = WAITCAT30C WAITCAT40C WAITCAT50C
; Does this answer your question? If so, here is the code of the actual macro: %macro metric_list (part0, part1, part2, part3, part4, part5, part6, part7, part8, part9, sep=_);
%local result result_temp;
%local level;
%local ix1 vx1;
%local ix2 vx2;
%let result = ;
%do level = 0 %to 9;
%if %length(&result.)=0 %then %do;
%let result = &&&part&level.;
%end; %else %if %length(&&&part&level.)~=0 %then %do;
%let result_temp = ;
%let ix1 = 1;
%let vx1 = %scan(&result., &ix1., %str( ));
%do %while(%length(&vx1.));
%let ix2 = 1;
%let vx2 = %scan(&&&part&level., &ix2., %str( ));
%do %while(%length(&vx2.));
%let result_temp = &result_temp. &vx1.&sep.&vx2.;
%let ix2 = %eval(&ix2. + 1);
%let vx2 = %scan(&&&part&level., &ix2., %str( ));
%end;
%let ix1 = %eval(&ix1. + 1);
%let vx1 = %scan(&result., &ix1., %str( ));
%end;
%let result = &result_temp.;
%end;
%end;
&result.
%mend metric_list;
%put TEST01: %metric_list(A, B, C, D, E, F, G, H, I, J);
%put TEST02: %metric_list(A, B, C, D, E, F, G, H, I, J, sep=);
%put TEST03: %metric_list(X, 0 1, 0 1, 0 1, 0 1, 0 1, 0 1, 0 1, 0 1, 0 1, sep=);
%put TEST04: %metric_list(revenue volume profit, period1 period2 period3 period4, prodA prodB prodC);
%put TEST05: %metric_list();
... View more