<?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: insert into in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-sql-insert-into/m-p/826158#M326328</link>
    <description>thank you! can I use alias for the tables to join the key? what's the syntax?</description>
    <pubDate>Fri, 29 Jul 2022 13:26:31 GMT</pubDate>
    <dc:creator>current_thing</dc:creator>
    <dc:date>2022-07-29T13:26:31Z</dc:date>
    <item>
      <title>PROC sql: insert into</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-sql-insert-into/m-p/826087#M326292</link>
      <description>&lt;P&gt;I have two SAS data sets with a common column called &lt;STRONG&gt;key&lt;/STRONG&gt;. I want to insert into table 2 a column called &lt;STRONG&gt;bill_complete_dt.&lt;/STRONG&gt;&amp;nbsp;I want to do a right join where &lt;STRONG&gt;key&lt;/STRONG&gt; on both tables match. I try this:&lt;/P&gt;&lt;PRE&gt;proc sql;

insert into my.&amp;amp;file2
select a.bill_complete_dt from my.&amp;amp;file1 as a right join my.&amp;amp;file2 as b on a.key=b.key;

quit;&lt;/PRE&gt;&lt;P&gt;I get the following error mesg:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;ERROR: Attempt to insert fewer columns than specified after the INSERT table name.&lt;BR /&gt;ERROR: Value 1 on the SELECT clause does not match the data type of the corresponding column listed after the INSERT table name.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;What I'm I doing wrong? Thanks for any help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jul 2022 01:32:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-sql-insert-into/m-p/826087#M326292</guid>
      <dc:creator>current_thing</dc:creator>
      <dc:date>2022-07-29T01:32:40Z</dc:date>
    </item>
    <item>
      <title>Re: PROC sql: insert into</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-sql-insert-into/m-p/826107#M326304</link>
      <description>&lt;P&gt;INSERT INTO adds &lt;EM&gt;complete observations&lt;/EM&gt;, and the values must match the structure of the existing dataset. You cannot use the statement to &lt;EM&gt;add a column&lt;/EM&gt; to the structure of the dataset. For this, you need to rewrite the dataset, either with CREATE TABLE in SQL, or with a DATA step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table my.file3 as /* do not immediately overwrite a dataset, in case something goes wrong */
  select
    t1.*,
    t2.bill_complete_dt
  from my.file2 t1 left join my.file1 t2
  on t1.key = t2.key
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jul 2022 06:40:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-sql-insert-into/m-p/826107#M326304</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-07-29T06:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: PROC sql: insert into</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-sql-insert-into/m-p/826119#M326307</link>
      <description>&lt;P&gt;In some scenarios you will want to perform two atomic operations on an existing data set (or remote data base table)&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;add a column to the table (alter)&lt;/LI&gt;
&lt;LI&gt;populate the column (update)&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;data one;
  input key a b c;
  datalines;
1 10 20 30
2 20 30 40
3 30 40 50
;

data two;
  input key (p q r) (3*:$1.);
  datalines;
1 A B C
2 D E F
3 G H I
4 J K L
5 M N P
;

proc sql;
  alter table two modify c num;
  update two
    set c = (select c from one where one.key=two.key)
  where
    exists  (select * from one where one.key=two.key)
  ;
&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jul 2022 08:26:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-sql-insert-into/m-p/826119#M326307</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2022-07-29T08:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: PROC sql: insert into</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-sql-insert-into/m-p/826158#M326328</link>
      <description>thank you! can I use alias for the tables to join the key? what's the syntax?</description>
      <pubDate>Fri, 29 Jul 2022 13:26:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-sql-insert-into/m-p/826158#M326328</guid>
      <dc:creator>current_thing</dc:creator>
      <dc:date>2022-07-29T13:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: PROC sql: insert into</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-sql-insert-into/m-p/826159#M326329</link>
      <description>thank you Kurt! this worked &lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;</description>
      <pubDate>Fri, 29 Jul 2022 13:27:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-sql-insert-into/m-p/826159#M326329</guid>
      <dc:creator>current_thing</dc:creator>
      <dc:date>2022-07-29T13:27:14Z</dc:date>
    </item>
  </channel>
</rss>

