<?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: Subsetting Dataset using Proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-Dataset-using-Proc-sql/m-p/486501#M126598</link>
    <description>I want to create a dataset from test_2. I edited my post. That was my bad.</description>
    <pubDate>Mon, 13 Aug 2018 22:34:25 GMT</pubDate>
    <dc:creator>AmirSari</dc:creator>
    <dc:date>2018-08-13T22:34:25Z</dc:date>
    <item>
      <title>Subsetting Dataset using Proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-Dataset-using-Proc-sql/m-p/486492#M126594</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to subset a dataset based on conditions that are true in another dataset. Basically, I have two datasets, say test_1 and test_2. The dataset test_1 also includes all observations in test_2. I want to drop the test_2 observations from the test_1 dataset. I tried to do that using proc sql but had no success so far.&lt;/P&gt;&lt;P&gt;Here is what I have.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table want as select *&lt;/P&gt;&lt;P&gt;from test_2&lt;/P&gt;&lt;P&gt;where YEAR not in (select YEAR from test_1) and ID not in (select ID from test_1);&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure what the problem is but I cannot get the sql to apply both conditions at the same time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help,&lt;/P&gt;</description>
      <pubDate>Mon, 13 Aug 2018 22:32:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-Dataset-using-Proc-sql/m-p/486492#M126594</guid>
      <dc:creator>AmirSari</dc:creator>
      <dc:date>2018-08-13T22:32:29Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting Dataset using Proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-Dataset-using-Proc-sql/m-p/486497#M126595</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/102358"&gt;@AmirSari&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;What is not working? What are you trying to achieve here?&lt;/P&gt;
&lt;P&gt;Your where clause will always be true so you won't get any rows returned. What you're doing here: You lookup if a value exists in the same table - that will always be true for any variable as you will always find at least one match (the variable matching with itself from the same row).&lt;/P&gt;</description>
      <pubDate>Mon, 13 Aug 2018 22:28:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-Dataset-using-Proc-sql/m-p/486497#M126595</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-08-13T22:28:48Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting Dataset using Proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-Dataset-using-Proc-sql/m-p/486498#M126596</link>
      <description>&lt;P&gt;You only use dataset test_1, which will naturally exclude itself completely.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Aug 2018 22:29:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-Dataset-using-Proc-sql/m-p/486498#M126596</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-13T22:29:07Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting Dataset using Proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-Dataset-using-Proc-sql/m-p/486501#M126598</link>
      <description>I want to create a dataset from test_2. I edited my post. That was my bad.</description>
      <pubDate>Mon, 13 Aug 2018 22:34:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-Dataset-using-Proc-sql/m-p/486501#M126598</guid>
      <dc:creator>AmirSari</dc:creator>
      <dc:date>2018-08-13T22:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting Dataset using Proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-Dataset-using-Proc-sql/m-p/486503#M126599</link>
      <description>I want to to create a dataset from test_2 where the observations that satisfy the two conditions are excluded.</description>
      <pubDate>Mon, 13 Aug 2018 22:35:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-Dataset-using-Proc-sql/m-p/486503#M126599</guid>
      <dc:creator>AmirSari</dc:creator>
      <dc:date>2018-08-13T22:35:57Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting Dataset using Proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-Dataset-using-Proc-sql/m-p/486506#M126600</link>
      <description>&lt;P&gt;If the variables in test_1 and test_2 are the same and you actually want to exclude the records that are in test_2 from test_1 then perhaps:&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table want as
   select * from test_1
   except 
   select * from test_2
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;However if the records are not actually identical, different variables for instance, this wouldn't quite work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In which case you can use except with a subset of variables to identify the records you want from test_1 and then join back with test_1 to get the other variables.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Aug 2018 22:39:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-Dataset-using-Proc-sql/m-p/486506#M126600</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-13T22:39:03Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting Dataset using Proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-Dataset-using-Proc-sql/m-p/486652#M126667</link>
      <description>&lt;P&gt;Maybe you need this in the future.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create table want as select *&lt;/P&gt;
&lt;P&gt;from test_2&lt;/P&gt;
&lt;P&gt;where catx(' ',YEAR,ID) not in (select&amp;nbsp; &lt;SPAN&gt;&amp;nbsp;catx(' ',YEAR,ID)&amp;nbsp; from&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN&gt;test_1&lt;/SPAN&gt; );&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Aug 2018 13:09:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-Dataset-using-Proc-sql/m-p/486652#M126667</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-08-14T13:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting Dataset using Proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-Dataset-using-Proc-sql/m-p/486753#M126702</link>
      <description>Thanks, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;!</description>
      <pubDate>Tue, 14 Aug 2018 17:08:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-Dataset-using-Proc-sql/m-p/486753#M126702</guid>
      <dc:creator>AmirSari</dc:creator>
      <dc:date>2018-08-14T17:08:26Z</dc:date>
    </item>
  </channel>
</rss>

