<?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 dataset depending on another dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-new-dataset-depending-on-another-dataset/m-p/792511#M253930</link>
    <description>&lt;P&gt;This is probably the most common approach, well understand by most SAS programmers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On the downside:&amp;nbsp; it requires sorted data sets.&amp;nbsp; (The other suggestions work on unsorted data.)&amp;nbsp; It might take slightly longer to run, but that is unlikely to be an issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note that the final statement could be simplified:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if not in2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any patient not found in IN2 must have come from IN1.&lt;/P&gt;</description>
    <pubDate>Wed, 26 Jan 2022 15:50:37 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2022-01-26T15:50:37Z</dc:date>
    <item>
      <title>Create new dataset depending on another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-dataset-depending-on-another-dataset/m-p/792478#M253914</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two data sets with patients, which all have an &lt;EM&gt;id&lt;/EM&gt;. The &lt;EM&gt;patients_all&lt;/EM&gt; dataset contains all patients, the &lt;EM&gt;patients_exclude&lt;/EM&gt; dataset contains the patients I want to exclude.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I want to create a dataset &lt;EM&gt;patients_all_clear&lt;/EM&gt; which contains all patients except those from the dataset &lt;EM&gt;patients_exclude&lt;/EM&gt;. The patients are identified by their id.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In short: various &lt;EM&gt;id&lt;/EM&gt; from the dataset &lt;EM&gt;patients_exclude&lt;/EM&gt; should no longer appear in the new dataset &lt;EM&gt;patients_all_clear&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What is the most clever way to do this?&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jan 2022 14:21:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-dataset-depending-on-another-dataset/m-p/792478#M253914</guid>
      <dc:creator>Tamino</dc:creator>
      <dc:date>2022-01-26T14:21:22Z</dc:date>
    </item>
    <item>
      <title>Re: Create new dataset depending on another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-dataset-depending-on-another-dataset/m-p/792484#M253918</link>
      <description>&lt;P&gt;Try something like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table patients_all_clear as select * from patients_all
        where id not in (select distinct id from patients_exclude);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Jan 2022 14:29:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-dataset-depending-on-another-dataset/m-p/792484#M253918</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-26T14:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: Create new dataset depending on another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-dataset-depending-on-another-dataset/m-p/792488#M253920</link>
      <description>&lt;P&gt;Most modern and most efficient method:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data patients_all_clear;
set patients_all;
if _n_ = 1
then do;
  declare hash ex (dataset:"patients_exclude");
  ex.definekey("id");
  ex.definedata("id"); /* not necessary, but reduces memory footprint */
  ex.definedone();
end;
if ex.check() = 0 /* id is found */ then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Jan 2022 14:41:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-dataset-depending-on-another-dataset/m-p/792488#M253920</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-01-26T14:41:23Z</dc:date>
    </item>
    <item>
      <title>Re: Create new dataset depending on another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-dataset-depending-on-another-dataset/m-p/792504#M253927</link>
      <description>&lt;P&gt;I tried:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data patients_all_clear;
     merge	patients_all	(in = in1)
         	patients_exclude    (in = in2);
     by id;
     if in1 and not in2;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Could there be a reason not to do it like this, or is it possible like this?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jan 2022 15:31:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-dataset-depending-on-another-dataset/m-p/792504#M253927</guid>
      <dc:creator>Tamino</dc:creator>
      <dc:date>2022-01-26T15:31:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create new dataset depending on another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-dataset-depending-on-another-dataset/m-p/792511#M253930</link>
      <description>&lt;P&gt;This is probably the most common approach, well understand by most SAS programmers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On the downside:&amp;nbsp; it requires sorted data sets.&amp;nbsp; (The other suggestions work on unsorted data.)&amp;nbsp; It might take slightly longer to run, but that is unlikely to be an issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note that the final statement could be simplified:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if not in2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any patient not found in IN2 must have come from IN1.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jan 2022 15:50:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-dataset-depending-on-another-dataset/m-p/792511#M253930</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-01-26T15:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: Create new dataset depending on another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-dataset-depending-on-another-dataset/m-p/792543#M253945</link>
      <description>&lt;P&gt;If the datasets are already sorted by id, you can do this, and it will perform fine. Be careful which variables are contained in the datasets, because you might overwrite values you want to keep.&lt;/P&gt;
&lt;P&gt;The hash method allows to use a lookup table without having to sort any of the datasets, as the sort is performed implicitly in memory when the key table is built.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jan 2022 17:02:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-dataset-depending-on-another-dataset/m-p/792543#M253945</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-01-26T17:02:46Z</dc:date>
    </item>
    <item>
      <title>Re: Create new dataset depending on another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-dataset-depending-on-another-dataset/m-p/796273#M255501</link>
      <description>&lt;P&gt;And I found a (very slight) code improvement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if ex.check() = 0 then delete;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;can be shortened to a subsetting if:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if ex.check() ne 0;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Feb 2022 14:18:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-dataset-depending-on-another-dataset/m-p/796273#M255501</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-02-15T14:18:07Z</dc:date>
    </item>
  </channel>
</rss>

