<?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: Create new table via Proc SQL with Multiple Select Statement Results in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-new-table-via-Proc-SQL-with-Multiple-Select-Statement/m-p/590351#M168948</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table table_info as
select 
(select count(*) as var1 from dbschema.tab1 ) as var1,
(select count (distinct id) as var2 from dbschema.tab2 ) as var2,
(select max (run_dt) as var3 from dbschema.tab3 ) as var3

from dbschema.tab1(obs=1) ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 20 Sep 2019 12:27:58 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2019-09-20T12:27:58Z</dc:date>
    <item>
      <title>Create new table via Proc SQL with Multiple Select Statement Results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-table-via-Proc-SQL-with-Multiple-Select-Statement/m-p/590190#M168875</link>
      <description>&lt;P&gt;I'm trying to create a new table called table_info using proc sql. The table will consist of three variables: var1, var2, var3 with each of the variables being the result of a select statement. How can I modify the following code? Please respond with short code examples.&amp;nbsp; Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 

proc sql;
create table table_info as
select count(*) as var1 from dbschema.tab1;
select count (distinct id) as var2 from dbschema.tab2;
select max (run_dt) as var3 from dbschema.tab3;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 20:25:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-table-via-Proc-SQL-with-Multiple-Select-Statement/m-p/590190#M168875</guid>
      <dc:creator>ijm_wf</dc:creator>
      <dc:date>2019-09-19T20:25:38Z</dc:date>
    </item>
    <item>
      <title>Re: Create new table via Proc SQL with Multiple Select Statement Results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-table-via-Proc-SQL-with-Multiple-Select-Statement/m-p/590201#M168877</link>
      <description>&lt;P&gt;For your exact example this should work&lt;/P&gt;
&lt;PRE&gt;proc sql;
create table table_info as
  select a.var1, b.var2, c.var3
  from 
      (select count(*) as var1 from dbschema.tab1) as a,
      (select count (distinct id) as var2 from dbschema.tab2) as b,
      (select max (run_dt) as var3 from dbschema.tab3) as c
  ;
quit;&lt;/PRE&gt;
&lt;P&gt;You will likely get a note about a cartesian product in the log.&lt;/P&gt;
&lt;P&gt;If you have something in the individual tables to group the data then likely you will want some form of Join on the group by variables&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 20:54:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-table-via-Proc-SQL-with-Multiple-Select-Statement/m-p/590201#M168877</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-09-19T20:54:33Z</dc:date>
    </item>
    <item>
      <title>Re: Create new table via Proc SQL with Multiple Select Statement Results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-table-via-Proc-SQL-with-Multiple-Select-Statement/m-p/590220#M168879</link>
      <description>&lt;P&gt;If you want to avoid the note about cartesian join, you can do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table myTable (var1 num, var2 num, var3 num);
insert into myTable
set 
    var1 = (select max(weight) from sashelp.class),
    var2 = (select max(weight) from sashelp.cars),
    var3 = (select max(weight) from sashelp.heart);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Sep 2019 21:48:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-table-via-Proc-SQL-with-Multiple-Select-Statement/m-p/590220#M168879</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-09-19T21:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create new table via Proc SQL with Multiple Select Statement Results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-table-via-Proc-SQL-with-Multiple-Select-Statement/m-p/590351#M168948</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table table_info as
select 
(select count(*) as var1 from dbschema.tab1 ) as var1,
(select count (distinct id) as var2 from dbschema.tab2 ) as var2,
(select max (run_dt) as var3 from dbschema.tab3 ) as var3

from dbschema.tab1(obs=1) ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Sep 2019 12:27:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-table-via-Proc-SQL-with-Multiple-Select-Statement/m-p/590351#M168948</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-09-20T12:27:58Z</dc:date>
    </item>
  </channel>
</rss>

