<?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: conditional joining of multiple files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/conditional-joining-of-multiple-files/m-p/684957#M207672</link>
    <description>unfortunately it depends on &amp;amp;i</description>
    <pubDate>Fri, 18 Sep 2020 12:45:00 GMT</pubDate>
    <dc:creator>makset</dc:creator>
    <dc:date>2020-09-18T12:45:00Z</dc:date>
    <item>
      <title>conditional joining of multiple files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-joining-of-multiple-files/m-p/684951#M207669</link>
      <description>&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN title=""&gt;We use the following scheme many times in my programs.&lt;/SPAN&gt; &lt;SPAN title=""&gt;I am retrieving data from multiple tables that meet certain conditions and a link to the final table.&lt;/SPAN&gt; &lt;SPAN title=""&gt;Many times the loop has over 1000 iterations and it works forever :).&lt;/SPAN&gt; &lt;SPAN title=""&gt;It can be optimized somehow, reducing the operating time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN title=""&gt;The code below is psudo code and I hope it is readable.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list=a b c d e f g h i j k l m n o p; *	and so on;
%let nwords=%sysfunc(countw(&amp;amp;list));

%macro loop();
%do i = 1 %to &amp;amp;nwords;
	%if &amp;amp;i = 1 %then %do; 

		data test;
		set %scan(&amp;amp;list, &amp;amp;i);
		if /*condition/**/;
		run;

	%end;
	%else %do;

		data temp;
		set %scan(&amp;amp;list, &amp;amp;i);
		if /*condition/**/;
		run;

		data test;
		set test temp;
		run;

	%end;
%end;
%mend loop;

%loop;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class="alt-edited" title=""&gt;Best regards&lt;/SPAN&gt;.&lt;BR /&gt;&lt;SPAN class="" title=""&gt;Thank you for your help.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2020 12:29:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-joining-of-multiple-files/m-p/684951#M207669</guid>
      <dc:creator>makset</dc:creator>
      <dc:date>2020-09-18T12:29:12Z</dc:date>
    </item>
    <item>
      <title>Re: conditional joining of multiple files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-joining-of-multiple-files/m-p/684953#M207670</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does the condition depend on &amp;amp;i. ?&lt;/P&gt;
&lt;P&gt;If not, can't you just do :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
    set &amp;amp;list.;
    if /* condition */
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Sep 2020 12:35:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-joining-of-multiple-files/m-p/684953#M207670</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2020-09-18T12:35:13Z</dc:date>
    </item>
    <item>
      <title>Re: conditional joining of multiple files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-joining-of-multiple-files/m-p/684955#M207671</link>
      <description>&lt;P&gt;Try next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list=a b c d e f g h i j k l m n o p; *	and so on;
%let nwords=%sysfunc(countw(&amp;amp;list));

%macro loop();
%do i = 1 %to &amp;amp;nwords;
	%if &amp;amp;i = 1 %then %do; 
	    proc datasets lib=work; delete test; quit;
	%end;
        proc append base=test 
		     data=%scan(&amp;amp;list, &amp;amp;i) 
			      (where=(&amp;lt;condition))  FORCE;
		run;		  
%end;
%mend loop;

%loop;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Sep 2020 12:41:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-joining-of-multiple-files/m-p/684955#M207671</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-09-18T12:41:50Z</dc:date>
    </item>
    <item>
      <title>Re: conditional joining of multiple files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-joining-of-multiple-files/m-p/684957#M207672</link>
      <description>unfortunately it depends on &amp;amp;i</description>
      <pubDate>Fri, 18 Sep 2020 12:45:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-joining-of-multiple-files/m-p/684957#M207672</guid>
      <dc:creator>makset</dc:creator>
      <dc:date>2020-09-18T12:45:00Z</dc:date>
    </item>
    <item>
      <title>Re: conditional joining of multiple files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-joining-of-multiple-files/m-p/684958#M207673</link>
      <description>small correction, condition 'if' depends on &amp;amp;i</description>
      <pubDate>Fri, 18 Sep 2020 12:46:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-joining-of-multiple-files/m-p/684958#M207673</guid>
      <dc:creator>makset</dc:creator>
      <dc:date>2020-09-18T12:46:39Z</dc:date>
    </item>
    <item>
      <title>Re: conditional joining of multiple files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-joining-of-multiple-files/m-p/684974#M207679</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17744"&gt;@makset&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;small correction, condition 'if' depends on &amp;amp;i&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You can assign the conditions in macro variables per input then use next adjusted code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list=a b c d e f g h i j k l m n o p; *	and so on;
%let nwords=%sysfunc(countw(&amp;amp;list));&lt;BR /&gt;%let cond1 = &amp;lt;condition foe dataset 1&amp;gt;;&lt;BR /&gt;...

%macro loop();
%do i = 1 %to &amp;amp;nwords;
	%if &amp;amp;i = 1 %then %do; 
	    proc datasets lib=work; delete test; quit;
	%end;
        proc append base=test 
		     data=%scan(&amp;amp;list, &amp;amp;i) 
			      (where=(&amp;amp;&amp;amp;cond&amp;amp;i)  FORCE;
		run;		  
%end;
%mend loop;

%loop;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;If conditions are constants and depended on the dataset you can enter them in a table&lt;/P&gt;
&lt;P&gt;in order to create the macro variables &amp;amp;&amp;amp;cond&amp;amp;i grammatically..&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2020 14:00:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-joining-of-multiple-files/m-p/684974#M207679</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-09-18T14:00:38Z</dc:date>
    </item>
    <item>
      <title>Re: conditional joining of multiple files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-joining-of-multiple-files/m-p/684982#M207684</link>
      <description>&lt;P&gt;Warning: bad things eventually happen to people that rely on code that has macro variables just "appear" in the body of a macro.&lt;/P&gt;
&lt;P&gt;You&amp;nbsp; would be much better off defining your macro with an actual parameter to contain the list and count the elements internally in the macro.Even if the macro variable such as your list already exists you can pass it as a parameter such as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro loop (locallist = &amp;amp;list);&lt;/P&gt;
&lt;P&gt;then use &amp;amp;locallist in a local countw and scan.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One of things that can happen with the "drop in" macro variables is you may change the value of list and elsewhere the change is used when you may not intend it.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2020 14:23:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-joining-of-multiple-files/m-p/684982#M207684</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-18T14:23:04Z</dc:date>
    </item>
    <item>
      <title>Re: conditional joining of multiple files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-joining-of-multiple-files/m-p/684990#M207689</link>
      <description>&lt;P&gt;What about maintaining a table - maybe by excel - containing few columns:&lt;/P&gt;
&lt;P&gt;1) input dataset name&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) condition for sub-setting relevant observations&lt;/P&gt;
&lt;P&gt;3) yes/no flag - should this row participate in current run&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;then transfer the data from the table to macro variables to be used with&lt;/P&gt;
&lt;P&gt;macro %loop or alternatively use call execute to submit the code to run&lt;/P&gt;
&lt;P&gt;adapted to current row, or even &lt;STRONG&gt;generate&lt;/STRONG&gt; code like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30622"&gt;@gamotte&lt;/a&gt;&amp;nbsp;posted:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want
  set &amp;lt;input1&amp;gt;(where=(&amp;lt;condition1&amp;gt;))
       &amp;lt;input2&amp;gt;(where=(&amp;lt;condition2&amp;gt;))
      ....
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Sep 2020 14:47:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-joining-of-multiple-files/m-p/684990#M207689</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-09-18T14:47:34Z</dc:date>
    </item>
  </channel>
</rss>

