<?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 SQL through a list of file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SQL-through-a-list-of-file/m-p/502930#M134312</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have a list of file with name say, one two three ...&lt;/P&gt;
&lt;P&gt;They all have the same number of row and&lt;U&gt; they all have a variable &lt;STRONG&gt;date&lt;/STRONG&gt;&lt;/U&gt;.&lt;/P&gt;
&lt;P&gt;I want to run the below SQL code on all combinations of file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so there will be ouput file onetwo ,onethree, twothree .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you help me to create a Loop to do it?&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HHCFX&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table onetwo
as select * from one join two
from a.date=b.date;quit; &lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 09 Oct 2018 22:56:56 GMT</pubDate>
    <dc:creator>hhchenfx</dc:creator>
    <dc:date>2018-10-09T22:56:56Z</dc:date>
    <item>
      <title>SQL through a list of file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-through-a-list-of-file/m-p/502930#M134312</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have a list of file with name say, one two three ...&lt;/P&gt;
&lt;P&gt;They all have the same number of row and&lt;U&gt; they all have a variable &lt;STRONG&gt;date&lt;/STRONG&gt;&lt;/U&gt;.&lt;/P&gt;
&lt;P&gt;I want to run the below SQL code on all combinations of file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so there will be ouput file onetwo ,onethree, twothree .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you help me to create a Loop to do it?&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HHCFX&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table onetwo
as select * from one join two
from a.date=b.date;quit; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Oct 2018 22:56:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-through-a-list-of-file/m-p/502930#M134312</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2018-10-09T22:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: SQL through a list of file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-through-a-list-of-file/m-p/502938#M134314</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have the list of names in a data set? Does it include any needed library to find the sets? If you have a library name what do want for the output?&lt;/P&gt;
&lt;P&gt;What is longest name of the datasets involved? If your names are longer than 16 characters you have a strong possibility of exceeding the 32 character limit for data set names the way you combine them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This may get you started:&lt;/P&gt;
&lt;PRE&gt;data listdataset;
   informat name $41.;
   input name;
datalines;
one
two 
three
alongerset
;
run;

proc sql;
   create table control as
   select a.name, b.name as bname
   from listdataset as a, listdataset as b
   where a.name lt b.name
   ;
quit;

data _null_;
   set control;
   call execute ('proc sql; create table '||
      cats(name,bname)||'as select'|| 
        catx(',',catx(',',name,'*'), catx(',',bname,'*'))||
     'from '|| name||' join '|| bname ||
     'from ' catx('=',catx('.',name,'date'), catx('.',bname,'date') )||
    ';quit;');
run;&lt;/PRE&gt;
&lt;P&gt;Caution: if combinations of your data set names aren't unique you won't get what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;TE NT and&lt;/P&gt;
&lt;P&gt;T&amp;nbsp; ENT would both try to create TENT. So only the last combination run would exist.&lt;/P&gt;
&lt;P&gt;If that might happen you would need to insert _ character between names to create TE_NT and T_ENT. Which reduces the number of characters allowed in the data set names by one per possible combination.&lt;/P&gt;
&lt;P&gt;You are going to get a low of warnings about the variable DATE in both sets. If you have any other variables with the same name in the data sets your results are unpredictable and possibly generate errors if they are not of the same type.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 23:23:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-through-a-list-of-file/m-p/502938#M134314</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-09T23:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: SQL through a list of file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-through-a-list-of-file/m-p/502940#M134316</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here we go&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	%let Rate_list= one two three;

	%macro BUYcode;
	%do i=1 %to %sysfunc(countw(&amp;amp;Rate_list));
			%let rate1=%scan(&amp;amp;Rate_list,&amp;amp;i);
	%do j=&amp;amp;i+1 %to %sysfunc(countw(&amp;amp;Rate_list));
			%let rate2=%scan(&amp;amp;Rate_list,&amp;amp;j);

			proc sql;
			create table &amp;amp;rate1._&amp;amp;rate2
			as select *
			from &amp;amp;rate1 as a join &amp;amp;rate2 as b
			on a.date=b.date;quit; 	
	%end;
	%end;
	%mend;

%BUYcode;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Oct 2018 23:49:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-through-a-list-of-file/m-p/502940#M134316</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2018-10-09T23:49:57Z</dc:date>
    </item>
  </channel>
</rss>

