<?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: use proc  SQL to update  whole column from another SAS dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355051#M273999</link>
    <description>&lt;P&gt;If you want to make table1 be a copy a table2?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table1 as select * from table2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you really want to join two tables of DIFFERENT sizes then I wouldn't use SQL.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  merge table1 table2 ;
  by id_var ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 01 May 2017 20:01:12 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-05-01T20:01:12Z</dc:date>
    <item>
      <title>use proc  SQL to update  whole column from another SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/354994#M273995</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to update table A by&amp;nbsp;table B with&amp;nbsp;proc sql?(after update, A&amp;nbsp;should has 100 rows)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data A;&lt;BR /&gt;do a=1 to 50;&lt;BR /&gt;b=int(ranuni( 12345 )*1000000);&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data B;&lt;BR /&gt;do a=1 to 100;&lt;BR /&gt;b=int(ranuni( 54321 )*1100000);&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 17:49:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/354994#M273995</guid>
      <dc:creator>GeorgeSAS</dc:creator>
      <dc:date>2017-05-01T17:49:30Z</dc:date>
    </item>
    <item>
      <title>Re: use proc  SQL to update  whole column from another SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355007#M273996</link>
      <description>&lt;P&gt;For pedagogical purposes, I changed the name of the tables and columns, but you'll find this code easier to understand (and others too, I hope).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will work.&amp;nbsp; Unfortunatley, you can't use the update procedures similar to the ones found in SQL Server, Oracle, and other populare database programs.&amp;nbsp; This is a bit of a workaround.&amp;nbsp; I hope this helps.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Table1;
do cola=1 to 50;
colb=int(ranuni( 12345 )*1000000);
output;
end;
run;

data Table2;
do cola=1 to 100;
colb=int(ranuni( 54321 )*1100000);
output;
end;
run;

proc sql;
update work.Table1
set
colb=(select colb from work.Table2 where Table1.cola=Table2.cola);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you simply want to add the rows from Table 1 to Table 2, use the followings:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
insert into Table1
select * from
Table2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 May 2017 18:24:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355007#M273996</guid>
      <dc:creator>statistician13</dc:creator>
      <dc:date>2017-05-01T18:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: use proc  SQL to update  whole column from another SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355047#M273997</link>
      <description>Thank you,&lt;BR /&gt;First method will update only 50 rows,&lt;BR /&gt;second method will append table2 to table1.&lt;BR /&gt;While I want table1 to be updated exactly same as table2. what I can do then?&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;BR /&gt;</description>
      <pubDate>Mon, 01 May 2017 19:53:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355047#M273997</guid>
      <dc:creator>GeorgeSAS</dc:creator>
      <dc:date>2017-05-01T19:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: use proc  SQL to update  whole column from another SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355049#M273998</link>
      <description>&lt;P&gt;Then it's not clear what you are wanting to do.&amp;nbsp; Can you provide an example using the first few values of Table1 and Table 2?&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 19:58:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355049#M273998</guid>
      <dc:creator>statistician13</dc:creator>
      <dc:date>2017-05-01T19:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: use proc  SQL to update  whole column from another SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355051#M273999</link>
      <description>&lt;P&gt;If you want to make table1 be a copy a table2?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table1 as select * from table2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you really want to join two tables of DIFFERENT sizes then I wouldn't use SQL.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  merge table1 table2 ;
  by id_var ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 May 2017 20:01:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355051#M273999</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-05-01T20:01:12Z</dc:date>
    </item>
    <item>
      <title>Re: use proc  SQL to update  whole column from another SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355052#M274000</link>
      <description>&lt;P&gt;Table1 is old data with only 50 rows.&lt;BR /&gt;table2 is new data. will has more rows(let's say 100 rows).&lt;BR /&gt;I want to create proc sql to update table1 using table2 as a lookup table.after update. table1 will be exact same as table2. it has 100 rows&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 20:04:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355052#M274000</guid>
      <dc:creator>GeorgeSAS</dc:creator>
      <dc:date>2017-05-01T20:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: use proc  SQL to update  whole column from another SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355054#M274001</link>
      <description>I have to use sql. I need to update an excel spreadsheet. which has lots of version limitation.</description>
      <pubDate>Mon, 01 May 2017 20:03:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355054#M274001</guid>
      <dc:creator>GeorgeSAS</dc:creator>
      <dc:date>2017-05-01T20:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: use proc  SQL to update  whole column from another SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355055#M274002</link>
      <description>&lt;P&gt;Not really a good idea to update an Excel spreadsheet. Excel is really not a database.&lt;/P&gt;
&lt;P&gt;If you are forced to use Excel then keep the data sheet separate from the presentation sheet that needs formatting.&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 20:09:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355055#M274002</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-05-01T20:09:28Z</dc:date>
    </item>
    <item>
      <title>Re: use proc  SQL to update  whole column from another SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355062#M274003</link>
      <description>&lt;P&gt;Make separate update and insert steps?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;update table1 
set colb = (select colb from table2 where table1.cola=table2.colb)
where cola in (select cola from table2)
;
insert into table1
select * from table2 
where cola not in (select cola from table1)
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 20:32:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355062#M274003</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-05-01T20:32:29Z</dc:date>
    </item>
    <item>
      <title>Re: use proc  SQL to update  whole column from another SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355112#M274004</link>
      <description>&lt;P&gt;There are two ways that are easily accessible (without writing your own look-up table function) that should get you what you need.&amp;nbsp; However, the first makes multiple sql statements, and the second isn't really an update, but it should accomplish what you need.&lt;BR /&gt;&lt;BR /&gt;This first option is a combination of the methods I already presented.&amp;nbsp; First, you update existing rows and then you have to insert rows that do not already exist in Table 1.&amp;nbsp; To accomplish this, you have to save your inital data to a temporary datasets (in this case work.temp):&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
update work.Table1
set
colb=(select colb from work.Table2 where Table1.cola=Table2.cola);
quit;

/*Create temporary table*/
proc sql;
create table work.temp as
select * from
Table1;
quit;

proc sql;
insert into Table1 
select * from
Table2
where
Table2.cola not in(select cola from temp);
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;The second appraoch does not update the table, but instead creates a new one (that can be presumably used to overwrite your existing data).&amp;nbsp; This appraoch performs a full out join on both tables and attempts to use any matching Colb record in table2 first.&amp;nbsp; if one is not found, it uses the record from Table1.&amp;nbsp; If no records are found, but it's a new records, the new record will be created.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table work.Table1 as
select
coalesce(b.colb, a.colb)
from
work.Table1 a FULL OUTER JOIN
work.Table2 b on
a.Cola=b.Cola;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 May 2017 00:54:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355112#M274004</guid>
      <dc:creator>statistician13</dc:creator>
      <dc:date>2017-05-02T00:54:39Z</dc:date>
    </item>
    <item>
      <title>Re: use proc  SQL to update  whole column from another SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355210#M274005</link>
      <description>&lt;P&gt;The only two ways I know which allow you to actually update/refresh a range/cells in an Excel sheet and not fully replace it are:&lt;/P&gt;
&lt;P&gt;1. DDE&lt;/P&gt;
&lt;P&gt;2. SAS AMO&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DDE is quite an outdated technique and even though it gives you the best "modular" access to Excel I can't recommend to use it as it locks you into a "problematic" very old-fashioned way of interacting with Excel (and you'll get into huge problems the day you need to migrate into a client-server environment).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS AMO: That could do the job nicely. You still couldn't fully automate the process though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...and that's why I totally agree with what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;proposes. That's the way which will cause you the least pain and which is the most future proof and will work in any SAS architecture.&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2017 12:04:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355210#M274005</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-05-02T12:04:42Z</dc:date>
    </item>
    <item>
      <title>Re: use proc  SQL to update  whole column from another SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355292#M274006</link>
      <description>Thank you for the reconfirm!&lt;BR /&gt;Maybe I will try DDE later, this will pain only on my computer,and the excel file from it will be fine for anyone.</description>
      <pubDate>Tue, 02 May 2017 15:50:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355292#M274006</guid>
      <dc:creator>GeorgeSAS</dc:creator>
      <dc:date>2017-05-02T15:50:38Z</dc:date>
    </item>
    <item>
      <title>Re: use proc  SQL to update  whole column from another SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355320#M274007</link>
      <description>&lt;P&gt;can't you update data using an OLE or ODBC connection to an Excel sheet or not?&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2017 17:13:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-proc-SQL-to-update-whole-column-from-another-SAS-dataset/m-p/355320#M274007</guid>
      <dc:creator>statistician13</dc:creator>
      <dc:date>2017-05-02T17:13:26Z</dc:date>
    </item>
  </channel>
</rss>

