<?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: Passing Macro Variable Lists in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Passing-Macro-Variable-Lists/m-p/626685#M184868</link>
    <description>&lt;P&gt;So...the solution that seems to work with my macro loop is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Define Route Waypoints */
%let RUBKI_EAST_1 = 'RUBKI' 'SIKBO' 'AHPAH';
%let RUBKI_EAST_2 = 'RUBKI' 'SIKBO' 'TULEG';
%let RUBKI_EAST_3 = 'RUBKI' 'KENLU' 'TULEG';
%let RUBKI_EAST_4 = 'RUBKI' 'SIKBO' 'OLABA' 'SAVAL' 'BUGSY';
%macro swaps_all (route_list=);
	%local n swap_var;
	%do n=1 %to %sysfunc(countw(&amp;amp;route_list));
		%let swap_var=%scan(&amp;amp;route_list,&amp;amp;n);

		proc sql;
			create table egtask.&amp;amp;swap_var as select * from EGTASK.CPL_KTOK
			where flt_biz_uid in (select flt_biz_uid from EGTASK.CPL_KTOK where flt_point_code in (&amp;amp;&amp;amp;&amp;amp;swap_var) group by flt_biz_uid having count(distinct flt_point_code)=countw("&amp;amp;&amp;amp;&amp;amp;swap_var",' '))
			order by flt_biz_uid, msg_biz_uid, flt_point_date;
		quit;

	%end;

%mend;
%swaps_all (route_list=RUBKI_EAST_1 RUBKI_EAST_2 RUBKI_EAST_3 RUBKI_EAST_4);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have 2 questions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; Why do I need 3 ampersands at: where flt_point_code in (&amp;amp;&amp;amp;&amp;amp;swap_var)&lt;/P&gt;&lt;P&gt;2. For the final part of the where clause it is:&amp;nbsp;having count(distinct flt_point_code)=countw("&amp;amp;&amp;amp;&amp;amp;swap_var",' '). I just put the 3 ampersands there on my own. I have discovered that it will work for 1. How many do I need?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In general, what is the rule for the amount of &amp;amp; to be used.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Almost there!&amp;nbsp; &amp;nbsp;Thanks in advance.&lt;/P&gt;</description>
    <pubDate>Sun, 23 Feb 2020 03:16:28 GMT</pubDate>
    <dc:creator>BCNAV</dc:creator>
    <dc:date>2020-02-23T03:16:28Z</dc:date>
    <item>
      <title>Passing Macro Variable Lists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-Macro-Variable-Lists/m-p/626666#M184860</link>
      <description>&lt;P&gt;I have flight data that has flight plans with waypoints for specific routes.&amp;nbsp; There are many different routes with different names. Two will be shown below. I need to be able to make route datasets. A route can contain a number of waypoints.&amp;nbsp; Here is the SAS:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Define Route Waypoints */
%let RUBKI_EAST_1 = "RUBKI" "SIKBO" "AHPAH";
%let RUBKI_EAST_2 = "RUBKI" "SIKBO" "TULEG";
%macro swaps_all (route_list=);
	%local n swap_var;
	%do n=1 %to %sysfunc(countw(&amp;amp;route_list));
		%let swap_var=%scan(&amp;amp;route_list,&amp;amp;n);

		proc sql;
			create table egtask.&amp;amp;swap_var as select * from EGTASK.CPL_KTOK
			where flt_biz_uid in (select flt_biz_uid from EGTASK.CPL_KTOK where flt_point_code in (&amp;amp;RUBKI_EAST_1))
			order by flt_biz_uid, msg_biz_uid, flt_point_date;
		quit;

	%end;

%mend;
%swaps_all (route_list=RUBKI_EAST_1 RUBKI_EAST_2);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It all works fine except for passing the new waypoints to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;where flt_point_code in (&amp;amp;RUBKI_EAST_1))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I increment the macro variables for the routes (which can have different names) to that where clause? Or am I going about this all wrong with the macro?&amp;nbsp; Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 22 Feb 2020 20:22:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-Macro-Variable-Lists/m-p/626666#M184860</guid>
      <dc:creator>BCNAV</dc:creator>
      <dc:date>2020-02-22T20:22:35Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Macro Variable Lists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-Macro-Variable-Lists/m-p/626667#M184861</link>
      <description>&lt;P&gt;Aren't you missing the ampersand &amp;amp; here&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macroname"&gt;%swaps_all&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;route_list&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;RUBKI_EAST_1 RUBKI_EAST_2&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which, shouldn't it be&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macroname"&gt;%swaps_all&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;route_list&lt;SPAN class="token operator"&gt;=&amp;amp;&lt;/SPAN&gt;RUBKI_EAST_1 &amp;amp;RUBKI_EAST_2&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Feb 2020 21:08:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-Macro-Variable-Lists/m-p/626667#M184861</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-02-22T21:08:18Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Macro Variable Lists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-Macro-Variable-Lists/m-p/626668#M184862</link>
      <description>&lt;P&gt;Are you tying to use the value of SWAP_VAR as the NAME of the macro variable whose value you want?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let RUBKI_EAST_1 = "RUBKI" "SIKBO" "AHPAH";
%let swap_var = RUBKI_EAST_1 ;
%put &amp;amp;&amp;amp;&amp;amp;swap_var ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where flt_point_code in (&amp;amp;&amp;amp;&amp;amp;swap_var)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Feb 2020 21:27:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-Macro-Variable-Lists/m-p/626668#M184862</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-22T21:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Macro Variable Lists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-Macro-Variable-Lists/m-p/626681#M184865</link>
      <description>&lt;P&gt;I think the &amp;amp;&amp;amp;&amp;amp;swap_var works.&amp;nbsp; Why do I need 3 &amp;amp;&amp;amp;&amp;amp;?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I think the logic is wrong. The staement:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where flt_point_code in (&amp;amp;RUBKI_EAST_1))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is multiple ors.&amp;nbsp; I want this to be multiple ands.&amp;nbsp; So in the example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let RUBKI_EAST_1 = "RUBKI" "SIKBO" "AHPAH";
%let RUBKI_EAST_2 = "RUBKI" "SIKBO" "TULEG";
%macro swaps_all (route_list=);
	%local n swap_var;
	%do n=1 %to %sysfunc(countw(&amp;amp;route_list));
		%let swap_var=%scan(&amp;amp;route_list,&amp;amp;n);
		%put &amp;amp;&amp;amp;&amp;amp;=swap_var;

		proc sql;
			create table egtask.&amp;amp;swap_var as select * from EGTASK.CPL_KTOK
			where flt_biz_uid in (select flt_biz_uid from EGTASK.CPL_KTOK where flt_point_code in (&amp;amp;RUBKI_EAST_1))
			order by flt_biz_uid, msg_biz_uid, flt_point_date;
		quit;

	%end;

%mend;
%swaps_all (route_list=RUBKI_EAST_1 RUBKI_EAST_2);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You will note that the two routes are similar.&amp;nbsp; Using the IN in the SQL is multiple ORs.&amp;nbsp; I do not want this. I want the specific waypoints for the route.&amp;nbsp; So for:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;%let RUBKI_EAST_1 = "RUBKI" "SIKBO" "AHPAH";&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;using IN effectively means RUBKI or SIKBO or AHPAH.&amp;nbsp; Is there a SQL that will make these effectively RUBKI and SIKBO and AHPAH?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Sat, 22 Feb 2020 22:58:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-Macro-Variable-Lists/m-p/626681#M184865</guid>
      <dc:creator>BCNAV</dc:creator>
      <dc:date>2020-02-22T22:58:32Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Macro Variable Lists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-Macro-Variable-Lists/m-p/626682#M184866</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/142314"&gt;@BCNAV&lt;/a&gt;&amp;nbsp; to make it an AND, Can you try&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where flt_biz_uid in
(select flt_biz_uid from EGTASK.CPL_KTOK where flt_point_code in (&amp;amp;RUBKI_EAST_1)
group by flt_biz_uid
having count(distinct flt_pt_code)=countw("&amp;amp;RUBKI_EAST_1",','))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;instead of&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select * from EGTASK.CPL_KTOK
			where flt_biz_uid in (select flt_biz_uid from EGTASK.CPL_KTOK where flt_point_code in (&amp;amp;RUBKI_EAST_1))
			order by flt_biz_uid, msg_biz_uid, flt_point_date;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Basically the idea is to Count the distinct values in&amp;nbsp;&lt;SPAN&gt;RUBKI_EAST_1 , and if equal to filtered records from the Where&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Feb 2020 23:15:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-Macro-Variable-Lists/m-p/626682#M184866</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-02-22T23:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Macro Variable Lists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-Macro-Variable-Lists/m-p/626685#M184868</link>
      <description>&lt;P&gt;So...the solution that seems to work with my macro loop is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Define Route Waypoints */
%let RUBKI_EAST_1 = 'RUBKI' 'SIKBO' 'AHPAH';
%let RUBKI_EAST_2 = 'RUBKI' 'SIKBO' 'TULEG';
%let RUBKI_EAST_3 = 'RUBKI' 'KENLU' 'TULEG';
%let RUBKI_EAST_4 = 'RUBKI' 'SIKBO' 'OLABA' 'SAVAL' 'BUGSY';
%macro swaps_all (route_list=);
	%local n swap_var;
	%do n=1 %to %sysfunc(countw(&amp;amp;route_list));
		%let swap_var=%scan(&amp;amp;route_list,&amp;amp;n);

		proc sql;
			create table egtask.&amp;amp;swap_var as select * from EGTASK.CPL_KTOK
			where flt_biz_uid in (select flt_biz_uid from EGTASK.CPL_KTOK where flt_point_code in (&amp;amp;&amp;amp;&amp;amp;swap_var) group by flt_biz_uid having count(distinct flt_point_code)=countw("&amp;amp;&amp;amp;&amp;amp;swap_var",' '))
			order by flt_biz_uid, msg_biz_uid, flt_point_date;
		quit;

	%end;

%mend;
%swaps_all (route_list=RUBKI_EAST_1 RUBKI_EAST_2 RUBKI_EAST_3 RUBKI_EAST_4);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have 2 questions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; Why do I need 3 ampersands at: where flt_point_code in (&amp;amp;&amp;amp;&amp;amp;swap_var)&lt;/P&gt;&lt;P&gt;2. For the final part of the where clause it is:&amp;nbsp;having count(distinct flt_point_code)=countw("&amp;amp;&amp;amp;&amp;amp;swap_var",' '). I just put the 3 ampersands there on my own. I have discovered that it will work for 1. How many do I need?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In general, what is the rule for the amount of &amp;amp; to be used.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Almost there!&amp;nbsp; &amp;nbsp;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Feb 2020 03:16:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-Macro-Variable-Lists/m-p/626685#M184868</guid>
      <dc:creator>BCNAV</dc:creator>
      <dc:date>2020-02-23T03:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Macro Variable Lists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-Macro-Variable-Lists/m-p/626686#M184869</link>
      <description>&lt;P&gt;Though I understand the concepts pretty well, It's only fair and good for us to request the explanation by sage&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; &amp;nbsp;whose advise/suggestions have benefitted numerous people including me. So, I am gonna wait with you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In any case, when Tom chimes in with an explanation I would expect most sane participants to listen and collobaorate&lt;EM&gt; willy&lt;SPAN&gt;-&lt;/SPAN&gt;nilly&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Feb 2020 04:52:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-Macro-Variable-Lists/m-p/626686#M184869</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-02-23T04:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Macro Variable Lists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-Macro-Variable-Lists/m-p/626696#M184871</link>
      <description>&lt;P&gt;When the macro processor sees two ampersands it converts them to one and reminds itself to reprocess that word again.&lt;/P&gt;
&lt;P&gt;So you have &amp;amp;&amp;amp; mapping to &amp;amp; and &amp;amp;SWAP_VAR mapping to&amp;nbsp;RUBKI_EAST_1. So when does the second pass it sees &amp;amp;RUBKI_EAST_1 and replaces thta.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can see it in action if you turn on the SYMBOLGEN option.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Feb 2020 05:18:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-Macro-Variable-Lists/m-p/626696#M184871</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-23T05:18:37Z</dc:date>
    </item>
  </channel>
</rss>

