<?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: apply queries to more than one table in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/apply-queries-to-more-than-one-table/m-p/68086#M19492</link>
    <description>i feel you can also do in this way&lt;BR /&gt;
&lt;BR /&gt;
%let s1=table1; * input table name1;&lt;BR /&gt;
%let s2=outputtale1; * output table name;&lt;BR /&gt;
%let s3=ap1; * all your append files dataset;&lt;BR /&gt;
&lt;BR /&gt;
* if your exporting all your files from the external source you can use &amp;amp;s1, &amp;amp;s2  in proc import;&lt;BR /&gt;
data libname.&amp;amp;s2; * if you want to save all your specific tables in a library;&lt;BR /&gt;
set &amp;amp;s1;&lt;BR /&gt;
keep col1 col2 col3 ......;&lt;BR /&gt;
run;&lt;BR /&gt;
* you can stop here if you want seperate tables;&lt;BR /&gt;
&lt;BR /&gt;
proc appennd base=&amp;amp;s2   data=&amp;amp;s3;&lt;BR /&gt;
run;&lt;BR /&gt;
or &lt;BR /&gt;
data tablename;&lt;BR /&gt;
set &amp;amp;s2 &amp;amp;s3.....;&lt;BR /&gt;
run;</description>
    <pubDate>Tue, 13 Jan 2009 11:13:28 GMT</pubDate>
    <dc:creator>ssas</dc:creator>
    <dc:date>2009-01-13T11:13:28Z</dc:date>
    <item>
      <title>apply queries to more than one table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/apply-queries-to-more-than-one-table/m-p/68084#M19490</link>
      <description>Hi&lt;BR /&gt;
&lt;BR /&gt;
I have 11 tables that i want to run a query to extract certain data (columns) from.&lt;BR /&gt;
all tables have same column's names&lt;BR /&gt;
&lt;BR /&gt;
how can i create a query to extract the columns i need from all tables? &lt;BR /&gt;
&lt;BR /&gt;
each table has like 100 columns so its hideous to do it 11 times! there should be a smarter way to do it... &lt;BR /&gt;
&lt;BR /&gt;
(I am a newbie btw)</description>
      <pubDate>Wed, 07 Jan 2009 16:05:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/apply-queries-to-more-than-one-table/m-p/68084#M19490</guid>
      <dc:creator>Bloker</dc:creator>
      <dc:date>2009-01-07T16:05:07Z</dc:date>
    </item>
    <item>
      <title>Re: apply queries to more than one table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/apply-queries-to-more-than-one-table/m-p/68085#M19491</link>
      <description>A macro would be a good way to handle this.  Put your query into the macro and then just run it 11 times, each time with a new dataset name. In the example below, each loop of the macro creates a tmpfile which is then appended to a master outfile.  The tmpfile is then deleted to prepare for the next macro invocation.&lt;BR /&gt;
&lt;BR /&gt;
Example:&lt;BR /&gt;
[pre]&lt;BR /&gt;
%macro runquery (infile=, outfile=);&lt;BR /&gt;
&lt;BR /&gt;
	proc sql;&lt;BR /&gt;
		create tmpfile as&lt;BR /&gt;
		select col1, col3, col5&lt;BR /&gt;
		from &amp;amp;infile;&lt;BR /&gt;
	quit;&lt;BR /&gt;
&lt;BR /&gt;
	proc append base=&amp;amp;outfile data=tmpfile;&lt;BR /&gt;
	run;&lt;BR /&gt;
&lt;BR /&gt;
	proc datasets library=work nolist;&lt;BR /&gt;
		delete tmpfile;&lt;BR /&gt;
	run;&lt;BR /&gt;
	quit;&lt;BR /&gt;
&lt;BR /&gt;
%mend runquery;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%runquery (infile=work.table1, outfile=work.endtable);&lt;BR /&gt;
%runquery (infile=work.table2, outfile=work.endtable);&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
%runquery (infile=work.table11, outfile=work.endtable);&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 07 Jan 2009 18:03:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/apply-queries-to-more-than-one-table/m-p/68085#M19491</guid>
      <dc:creator>1162</dc:creator>
      <dc:date>2009-01-07T18:03:10Z</dc:date>
    </item>
    <item>
      <title>Re: apply queries to more than one table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/apply-queries-to-more-than-one-table/m-p/68086#M19492</link>
      <description>i feel you can also do in this way&lt;BR /&gt;
&lt;BR /&gt;
%let s1=table1; * input table name1;&lt;BR /&gt;
%let s2=outputtale1; * output table name;&lt;BR /&gt;
%let s3=ap1; * all your append files dataset;&lt;BR /&gt;
&lt;BR /&gt;
* if your exporting all your files from the external source you can use &amp;amp;s1, &amp;amp;s2  in proc import;&lt;BR /&gt;
data libname.&amp;amp;s2; * if you want to save all your specific tables in a library;&lt;BR /&gt;
set &amp;amp;s1;&lt;BR /&gt;
keep col1 col2 col3 ......;&lt;BR /&gt;
run;&lt;BR /&gt;
* you can stop here if you want seperate tables;&lt;BR /&gt;
&lt;BR /&gt;
proc appennd base=&amp;amp;s2   data=&amp;amp;s3;&lt;BR /&gt;
run;&lt;BR /&gt;
or &lt;BR /&gt;
data tablename;&lt;BR /&gt;
set &amp;amp;s2 &amp;amp;s3.....;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 13 Jan 2009 11:13:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/apply-queries-to-more-than-one-table/m-p/68086#M19492</guid>
      <dc:creator>ssas</dc:creator>
      <dc:date>2009-01-13T11:13:28Z</dc:date>
    </item>
  </channel>
</rss>

