<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Multi-dimensional macros in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multi-dimensional-macros/m-p/830013#M327952</link>
    <description>&lt;P&gt;I would suggest a macro with two arguments, each of them a list.&amp;nbsp; The first is a list of types, the second a list of list values, as in:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro doranks(types=,list=);
  %do t=1 %to %sysfunc(countw(&amp;amp;types));
    %let type=%scan(&amp;amp;types,&amp;amp;t);
    %do L=1 %to %sysfunc(countw(&amp;amp;list));
      %let listitem=%scan(&amp;amp;list,&amp;amp;L);
      proc rank data=scored_&amp;amp;type._&amp;amp;listitem out=ranked_&amp;amp;type._&amp;amp;listitem groups=100 descending;
        var p_target1;
        ranks CF_score_rank_a;
        where train=0;
      run;
    %end;
  %end;
%mend doranks;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can then call the "nested" loops in a single macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%doranks(types=DT LR RF,list=LIST_1 LIST_2);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 23 Aug 2022 23:06:56 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2022-08-23T23:06:56Z</dc:date>
    <item>
      <title>Multi-dimensional macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multi-dimensional-macros/m-p/830006#M327947</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working with the following six datasets:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;scored_DT_list_1&lt;BR /&gt;scored_LR_list_1&lt;BR /&gt;scored_RF_list_1&lt;BR /&gt;scored_DT_list_2&lt;BR /&gt;scored_LR_list_2&lt;BR /&gt;scored_RF_list_2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and would like to create the next six datasets:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ranked_DT_list_1&lt;BR /&gt;ranked_LR_list_1&lt;BR /&gt;ranked_RF_list_1&lt;BR /&gt;ranked_DT_list_2&lt;BR /&gt;ranked_LR_list_2&lt;BR /&gt;ranked_RF_list_2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;using either a loop or macro. I wanted to write an efficient, nested macro, but I am getting errors that the double ampersand macro variable (type) is not being resolved. This is the code block that is causing the error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro models(type);&lt;/P&gt;&lt;P&gt;%macro varlist(list);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc rank data=scored_&amp;amp;&amp;amp;type_&amp;amp;list out=ranked_&amp;amp;&amp;amp;type_&amp;amp;list groups=100 descending;&lt;BR /&gt;var P_Target1;&lt;BR /&gt;ranks CF_Score_Rank_a;&lt;BR /&gt;where train = 0;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%mend;&lt;BR /&gt;%varlist(list_1);&lt;BR /&gt;%varlist(list_2);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%Models(DT);&lt;BR /&gt;%Models(LR);&lt;BR /&gt;%Models(RF);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a better or more efficient way to write this type of loop?&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2022 21:44:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multi-dimensional-macros/m-p/830006#M327947</guid>
      <dc:creator>GuyTreepwood</dc:creator>
      <dc:date>2022-08-23T21:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: Multi-dimensional macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multi-dimensional-macros/m-p/830008#M327948</link>
      <description>&lt;P&gt;Nesting macro definitions is typically not done. It's buggy and usually unnecessary. It seems like you're trying to go across multiple variables at once. Is this example illustrative of your real problem, or is there more lists/variables? Depending on exactly how many dimensions there are different ways to scale this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro rank(type= , list=);

proc rank data=scored_&amp;amp;type_list_&amp;amp;list out=ranked_&amp;amp;type_list_&amp;amp;list groups=100 descending;
var P_Target1;
ranks CF_Score_Rank_a;
where train = 0;
run;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you want to run it for three different variables and two lists (1/2), so how you generate that call can vary. If the data sets already exist, I'd run it on all data sets in the work library that had that format of a name.&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data run_list;
set sashelp.vtable;
where libname = 'WORK' and memname like 'SCORED%';

type = scan(memname, 2, "_");
list = scan(memname, 4, "_");

str = catt('%rank(type=', type, ' , list=', list, ');');
call execute(str);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UNTESTED.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/77218"&gt;@GuyTreepwood&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am working with the following six datasets:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;scored_DT_list_1&lt;BR /&gt;scored_LR_list_1&lt;BR /&gt;scored_RF_list_1&lt;BR /&gt;scored_DT_list_2&lt;BR /&gt;scored_LR_list_2&lt;BR /&gt;scored_RF_list_2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and would like to create the next six datasets:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ranked_DT_list_1&lt;BR /&gt;ranked_LR_list_1&lt;BR /&gt;ranked_RF_list_1&lt;BR /&gt;ranked_DT_list_2&lt;BR /&gt;ranked_LR_list_2&lt;BR /&gt;ranked_RF_list_2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;using either a loop or macro. I wanted to write an efficient, nested macro, but I am getting errors that the double ampersand macro variable (type) is not being resolved. This is the code block that is causing the error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro models(type);&lt;/P&gt;
&lt;P&gt;%macro varlist(list);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc rank data=scored_&amp;amp;&amp;amp;type_&amp;amp;list out=ranked_&amp;amp;&amp;amp;type_&amp;amp;list groups=100 descending;&lt;BR /&gt;var P_Target1;&lt;BR /&gt;ranks CF_Score_Rank_a;&lt;BR /&gt;where train = 0;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mend;&lt;BR /&gt;%varlist(list_1);&lt;BR /&gt;%varlist(list_2);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;%Models(DT);&lt;BR /&gt;%Models(LR);&lt;BR /&gt;%Models(RF);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a better or more efficient way to write this type of loop?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2022 22:14:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multi-dimensional-macros/m-p/830008#M327948</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-08-23T22:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: Multi-dimensional macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multi-dimensional-macros/m-p/830009#M327949</link>
      <description>&lt;P&gt;I haven't tried to go thorugh your macros in detail, but if you want to take data set scored_DT_list_1 and do something to it and have an output that is named ranked_DT_list_1, then all you need to do is have a macro variable that contains the new data set name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let output_data_set_name=%sysfunc(tranwrd(&amp;amp;input_data_set_name,scored,ranked));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Agreeing with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; , do not nest macro definitions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2022 22:20:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multi-dimensional-macros/m-p/830009#M327949</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-08-23T22:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: Multi-dimensional macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multi-dimensional-macros/m-p/830013#M327952</link>
      <description>&lt;P&gt;I would suggest a macro with two arguments, each of them a list.&amp;nbsp; The first is a list of types, the second a list of list values, as in:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro doranks(types=,list=);
  %do t=1 %to %sysfunc(countw(&amp;amp;types));
    %let type=%scan(&amp;amp;types,&amp;amp;t);
    %do L=1 %to %sysfunc(countw(&amp;amp;list));
      %let listitem=%scan(&amp;amp;list,&amp;amp;L);
      proc rank data=scored_&amp;amp;type._&amp;amp;listitem out=ranked_&amp;amp;type._&amp;amp;listitem groups=100 descending;
        var p_target1;
        ranks CF_score_rank_a;
        where train=0;
      run;
    %end;
  %end;
%mend doranks;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can then call the "nested" loops in a single macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%doranks(types=DT LR RF,list=LIST_1 LIST_2);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Aug 2022 23:06:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multi-dimensional-macros/m-p/830013#M327952</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-08-23T23:06:56Z</dc:date>
    </item>
  </channel>
</rss>

