<?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: PROC SQL using list of tables in from in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-using-list-of-tables-in-from/m-p/632689#M77836</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;do you mean use of macroquoting function, like %STR()&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro first_macro(size, listOfFiles=);
%let list_var = var1 var2 var3 var4 var5;
%do i=1 %to &amp;amp;size;
 %let var = %scan(&amp;amp;list_var,&amp;amp;i);
	proc sql;
	create table table&amp;amp;i as
	select distinct &amp;amp;var
	from file
	quit;
%end;

PROC SQL;Create Table cross_1 as Select monotonic() as id_5,* from &amp;amp;listOfFiles.;Quit;
%mend;


%first_macro(5, listOfFiles=%str(table1,table2,table3,table4,table5));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Tue, 17 Mar 2020 15:00:12 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2020-03-17T15:00:12Z</dc:date>
    <item>
      <title>PROC SQL using list of tables in from</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-using-list-of-tables-in-from/m-p/632679#M77834</link>
      <description>&lt;P&gt;Hello for all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm new using SAS and PROC SQL.&amp;nbsp; I wrote a code to cartesian product with different values of 5 variables but i want to parameterize it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro first_macro(size);
%let list_var = var1 var2 var3 var4 var5;
%do i=1 %to &amp;amp;size;
 %let var = %scan(&amp;amp;list_var,&amp;amp;i);
	proc sql;
	create table table&amp;amp;i as
	select distinct &amp;amp;var
	from file
	quit;
%end;

PROC SQL;Create Table cross_1 as Select monotonic() as id_5,* from table1,table2,table3,table4,table5;Quit;
PROC SQL;Create Table cross_2 as Select monotonic() as id_4,* from table1,table2,table3,table4;Quit;
PROC SQL;Create Table cross_3 as Select monotonic() as id_3,* from table1,table2,table3;Quit;
PROC SQL;Create Table cross_4 as Select monotonic() as id_2,* from table1,table2;Quit;
PROC SQL;Create Table cross_5 as Select monotonic() as id_1,* from table1;Quit;

%mend;


%first_macro(5);&lt;/PRE&gt;&lt;P&gt;There is one way to declare a list of tables separated by ',' and using it in proc sql sentence with loop?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 14:32:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-using-list-of-tables-in-from/m-p/632679#M77834</guid>
      <dc:creator>liguang01</dc:creator>
      <dc:date>2020-03-17T14:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL using list of tables in from</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-using-list-of-tables-in-from/m-p/632689#M77836</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;do you mean use of macroquoting function, like %STR()&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro first_macro(size, listOfFiles=);
%let list_var = var1 var2 var3 var4 var5;
%do i=1 %to &amp;amp;size;
 %let var = %scan(&amp;amp;list_var,&amp;amp;i);
	proc sql;
	create table table&amp;amp;i as
	select distinct &amp;amp;var
	from file
	quit;
%end;

PROC SQL;Create Table cross_1 as Select monotonic() as id_5,* from &amp;amp;listOfFiles.;Quit;
%mend;


%first_macro(5, listOfFiles=%str(table1,table2,table3,table4,table5));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 15:00:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-using-list-of-tables-in-from/m-p/632689#M77836</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-03-17T15:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL using list of tables in from</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-using-list-of-tables-in-from/m-p/632690#M77837</link>
      <description>&lt;P&gt;Yes but i want to create cross_1, cross_2...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the first iteration it will have to use table1--table5. In the second, it will have to use table1--table4...&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 15:05:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-using-list-of-tables-in-from/m-p/632690#M77837</guid>
      <dc:creator>liguang01</dc:creator>
      <dc:date>2020-03-17T15:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL using list of tables in from</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-using-list-of-tables-in-from/m-p/632696#M77839</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Like that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro first_macro(size, listOfFiles=);
%let list_var = var1 var2 var3 var4 var5;
%do i=1 %to &amp;amp;size;
 %let var = %scan(&amp;amp;list_var,&amp;amp;i);
	proc sql;
	create table table&amp;amp;i as
	select distinct &amp;amp;var
	from file
	quit;
%end;

%do i=1 %to &amp;amp;size;
  PROC SQL;
  create table cross_&amp;amp;i as 
  select monotonic() as id_&amp;amp;i ,* 
  from table1 
    %do j=2 %to &amp;amp;i;
      ,%qscan(&amp;amp;listOfFiles., &amp;amp;j, %str(,))
    %end; 
  ;
  Quit;
%end;

%mend;

%first_macro(5, listOfFiles=%str(table1,table2,table3,table4,table5));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If it could be a space separate list of tables you could do it without %str()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro first_macro(size, listOfFiles=);
%let list_var = var1 var2 var3 var4 var5;
%do i=1 %to &amp;amp;size;
 %let var = %scan(&amp;amp;list_var,&amp;amp;i);
	proc sql;
	create table table&amp;amp;i as
	select distinct &amp;amp;var
	from file
	quit;
%end;

%do i=1 %to &amp;amp;size;
  PROC SQL;
  create table cross_&amp;amp;i as 
  select monotonic() as id_&amp;amp;i ,* 
  from table1 
    %do j=2 %to &amp;amp;i;
      ,%qscan(&amp;amp;listOfFiles., &amp;amp;j, %str( ))
    %end; 
  ;
  Quit;
%end;

%mend;

%first_macro(5, listOfFiles=table1 table2 table3 table4 table5);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 15:16:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-using-list-of-tables-in-from/m-p/632696#M77839</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-03-17T15:16:41Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL using list of tables in from</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-using-list-of-tables-in-from/m-p/632701#M77840</link>
      <description>&lt;P&gt;It is exact what i want thanks.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is&amp;nbsp; there is possible that you dont specify list of tables and the program catch it by &lt;STRONG&gt;size&lt;/STRONG&gt; (parameter of macro) ?&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 15:22:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-using-list-of-tables-in-from/m-p/632701#M77840</guid>
      <dc:creator>liguang01</dc:creator>
      <dc:date>2020-03-17T15:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL using list of tables in from</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-using-list-of-tables-in-from/m-p/632703#M77841</link>
      <description>&lt;P&gt;Yes,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro first_macro(size);
%let list_var = var1 var2 var3 var4 var5;
%do i=1 %to &amp;amp;size;
 %let var = %scan(&amp;amp;list_var,&amp;amp;i);
	proc sql;
	create table table&amp;amp;i as
	select distinct &amp;amp;var
	from file
	quit;
%end;

%do i=1 %to &amp;amp;size;
  PROC SQL;
  create table cross_&amp;amp;i as 
  select monotonic() as id_&amp;amp;i ,* 
  from table1 
    %do j=2 %to &amp;amp;i;
      ,table&amp;amp;j.
    %end; 
  ;
  Quit;
%end;

%mend;

%first_macro(5);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 15:26:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-using-list-of-tables-in-from/m-p/632703#M77841</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-03-17T15:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL using list of tables in from</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-using-list-of-tables-in-from/m-p/632707#M77842</link>
      <description>&lt;P&gt;DON"T use comma as the delimiter in your macro code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can have the macro put in the commas where they are needed.&lt;/P&gt;
&lt;P&gt;For example you could loop loop over the list of variables and then loop over the list of tables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mymacro(varlist,tablelist);
%local i j var sep;
proc sql;
%do i=1 %to %sysfunc(countw(&amp;amp;varlist,%str( )));
  %let var = %scan(&amp;amp;varlist,&amp;amp;i,%str( ));
create table table&amp;amp;i as
  select distinct &amp;amp;var
  from 
  %let sep=;
  %do j=1 %to %sysfunc(countw(&amp;amp;tablelist,%str( )));
     &amp;amp;sep.%scan(&amp;amp;tablelist,&amp;amp;j,%str( ))
    %let sep=,;
  %end;
;
%end;
quit;
%mend mymacro;
%mymacro(varlist=var1 var2 var3,tablelist=table1 table2 table3)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Mar 2020 15:46:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-using-list-of-tables-in-from/m-p/632707#M77842</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-17T15:46:17Z</dc:date>
    </item>
  </channel>
</rss>

