title: How can I use %SCAN within a macro variable name?
body: <p>I'm trying to write robust code to assign values to macro variables. I want the names of the macro variables to depend on values coming from the variable 'subgroup'. So subgroup could equal 1, 2, or 45 etc. and thus have macro variable names trta_1, trta_2, trt_45 etc.</p>
  
  <p>Where I am having difficulty is calling the macro variable name. So instead of calling e.g. &amp;trta_1 I want to call &amp;trta_%SCAN(&amp;subgroups, &amp;k), which resolves to trta_1 on the first iteration. I've used a %SCAN function in the macro variable name, which is throwing up a warning 'WARNING: Apparent symbolic reference TRTA_ not resolved.'. However, the macro variables have been created with values assigned. </p>
  
  <p>How can I resolve the warning? Is there a function I could run with the %SCAN function to get this to work?</p>
  
  <pre><code>data data1 ;
    input subgroup trta trtb ;
    datalines ;
    1 30 58
    2 120 450
    3 670 3
  run;
  
  %LET subgroups = 1 2 3 ;
  %PUT &amp;subgroups;
  
  %MACRO test;
    %DO k=1 %TO 3;
  
      DATA test_&amp;k;
        SET data1; 
        WHERE subgroup = %SCAN(&amp;subgroups, &amp;k);
        CALL SYMPUTX("TRTA_%SCAN(&amp;subgroups, &amp;k)", trta, 'G');
        CALL SYMPUTX("TRTB_%SCAN(&amp;subgroups, &amp;k)", trtb, 'G'); 
      RUN;  
  
      %PUT "&amp;TRTA_%SCAN(&amp;subgroups, &amp;k)" "&amp;TRTB_%SCAN(&amp;subgroups, &amp;k)"; 
    %END;
  
  %MEND test;
  %test;
  </code></pre>