<?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: Insert into using where before select in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Insert-into-using-where-before-select/m-p/622134#M182991</link>
    <description>&lt;P&gt;I don't think that's right. If I slightly Change the filter, it is still not working yet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
insert into have2(where=(age=20))
select * from have3;
quit;


proc sql;
select * from have2;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 04 Feb 2020 07:40:28 GMT</pubDate>
    <dc:creator>David_Billa</dc:creator>
    <dc:date>2020-02-04T07:40:28Z</dc:date>
    <item>
      <title>Insert into using where before select</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-into-using-where-before-select/m-p/622128#M182989</link>
      <description>&lt;P&gt;Could you please help me understand why the below INSERT INTO code is not working as excepted? I know that it will work if I code the WHERE after select clause but I would like to know why it is not working if I code before SELECT. How to make this work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* dataset 1*/
data have1;
input name $ age;
datalines;
bill 20
sam 10
ram 30
;
/* dataset 2*/
data have2;
input name $ age;
datalines;
bill 20
raj  40

;
/* create a temp table*/
proc sql;
create table have3 as
select * from have1
where trim(name) not in(select trim(name) from have2);
quit;

/* then insert into final table only age eq 20*/
proc sql;
insert into have2(where=(age=20))
select * from have3;
quit;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Feb 2020 07:41:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-into-using-where-before-select/m-p/622128#M182989</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-02-04T07:41:09Z</dc:date>
    </item>
    <item>
      <title>Re: Insert into using where before select</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-into-using-where-before-select/m-p/622129#M182990</link>
      <description>&lt;P&gt;This way you are applying the filter to Have2 and not Have3.&amp;nbsp;&lt;/P&gt;&lt;P&gt;And since you can't filter Have2 using INSERT INTO, no action is done&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 07:25:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-into-using-where-before-select/m-p/622129#M182990</guid>
      <dc:creator>Pmyosh</dc:creator>
      <dc:date>2020-02-04T07:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: Insert into using where before select</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-into-using-where-before-select/m-p/622134#M182991</link>
      <description>&lt;P&gt;I don't think that's right. If I slightly Change the filter, it is still not working yet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
insert into have2(where=(age=20))
select * from have3;
quit;


proc sql;
select * from have2;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Feb 2020 07:40:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-into-using-where-before-select/m-p/622134#M182991</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-02-04T07:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: Insert into using where before select</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-into-using-where-before-select/m-p/622141#M182996</link>
      <description>&lt;P&gt;Can you paste here the new filter that you applied?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In your new code/post, the filter is the same&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 08:21:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-into-using-where-before-select/m-p/622141#M182996</guid>
      <dc:creator>Pmyosh</dc:creator>
      <dc:date>2020-02-04T08:21:22Z</dc:date>
    </item>
    <item>
      <title>Re: Insert into using where before select</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-into-using-where-before-select/m-p/622142#M182997</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why don't you use the set operator 'union' to achieve this. It enables you to&amp;nbsp;&lt;SPAN&gt;combine the results of two SQL&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;queries into a single table as follows:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	select * from have2 where age=20
	union
	select * from have3;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Feb 2020 08:23:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-into-using-where-before-select/m-p/622142#M182997</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-04T08:23:21Z</dc:date>
    </item>
    <item>
      <title>Re: Insert into using where before select</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-into-using-where-before-select/m-p/622143#M182998</link>
      <description>&lt;P&gt;This is the new filter. Indeed I edited the new post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
insert into have2(where=(age=20))
select * from have3;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Feb 2020 08:25:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-into-using-where-before-select/m-p/622143#M182998</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-02-04T08:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: Insert into using where before select</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-into-using-where-before-select/m-p/622144#M182999</link>
      <description>&lt;P&gt;Insert into works on the physical table as it exists; it does never change any data that is already present, it only appends, therefore the where= dataset option is ignored.&lt;/P&gt;
&lt;P&gt;IMO, using a where= dataset option in this way should result in a WARNING, as it can't work &lt;EM&gt;by principle&lt;/EM&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 08:26:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-into-using-where-before-select/m-p/622144#M182999</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-04T08:26:04Z</dc:date>
    </item>
    <item>
      <title>Re: Insert into using where before select</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-into-using-where-before-select/m-p/622146#M183000</link>
      <description>&lt;P&gt;Thanks. But I no need any other way as the code which I have mentioned in the post is I get from DI Studio. I would like to know why it's not working and how to make that method works.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 08:27:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-into-using-where-before-select/m-p/622146#M183000</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-02-04T08:27:20Z</dc:date>
    </item>
    <item>
      <title>Re: Insert into using where before select</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-into-using-where-before-select/m-p/622150#M183002</link>
      <description>&lt;P&gt;There is no warning as you can see in the log below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;26         proc sql;
27         insert into have2(where=(age=20))
28         select * from have3;
NOTE: 2 rows were inserted into WORK.HAVE2.

29         quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
      &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Feb 2020 08:35:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-into-using-where-before-select/m-p/622150#M183002</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-02-04T08:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: Insert into using where before select</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-into-using-where-before-select/m-p/622152#M183003</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;There is no warning as you can see in the log below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;26         proc sql;
27         insert into have2(where=(age=20))
28         select * from have3;
NOTE: 2 rows were inserted into WORK.HAVE2.

29         quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
      &lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, and I consider that a bug. In your position, I would bring this to the attention of SAS technical support. Especially when you can create such &lt;EM&gt;in principle&lt;/EM&gt; invalid code with one of the GUI clients. The client should not allow you to do it, that's its function (IMO) as a support for those who can't (or don't want) to write the code themselves.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS the code given by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;is the valid method for this action, and it is the one that you should create (or be able to create) with DI Studio.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But there will always be things where the pointy-clicky helpers can't keep up with the good ol' Brain Mk 1. That's why I&amp;nbsp;&lt;EM&gt;write&lt;/EM&gt; my codes, and don't &lt;EM&gt;have them written&lt;/EM&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 14:26:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-into-using-where-before-select/m-p/622152#M183003</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-04T14:26:10Z</dc:date>
    </item>
    <item>
      <title>Re: Insert into using where before select</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-into-using-where-before-select/m-p/622235#M183032</link>
      <description>&lt;P&gt;Please explain better what you are trying to do.&lt;/P&gt;
&lt;P&gt;Code with dataset options on the target of the INSERT makes no sense.&amp;nbsp; If you only want to insert observations where AGE=20 then apply that to the code that is selecting which observations to insert.&amp;nbsp; Either of these methods would work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;insert into want
select * from have where age=20
;
insert into want
select * from have(where=(age=20))
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to eliminate observations from the target dataset then you need to use a DELETE statement and not an INSERT statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;delete from want where age=20;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Feb 2020 16:41:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-into-using-where-before-select/m-p/622235#M183032</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-04T16:41:23Z</dc:date>
    </item>
  </channel>
</rss>

