<?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: Creating dataset dropping all lines of IDs which are not listed in another dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-dataset-dropping-all-lines-of-IDs-which-are-not-listed/m-p/793692#M254413</link>
    <description>&lt;P&gt;Since you only need ID for your check, make sure that only this variable is read:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;merge
  dataset_A (
    in = in1
    keep = id
  )
  dataset_B (
    in = in2
  )
;
if in1 and in2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;otherwise values from dataset_b will overwrite values from dataset_a.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: moved the KEEP= option to dataset_a.&lt;/P&gt;</description>
    <pubDate>Tue, 01 Feb 2022 08:44:07 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-02-01T08:44:07Z</dc:date>
    <item>
      <title>Creating dataset dropping all lines of IDs which are not listed in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-dataset-dropping-all-lines-of-IDs-which-are-not-listed/m-p/793690#M254411</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two datasets, that I need to combine in a specific way, and I can't seem to get what I need. Any help greatly appreciated. I'm not sure if I'm using the wrong command here....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;What I need to do is&lt;/STRONG&gt;: I want to create a dataset, which contains all lines of dataset B, which start with an ID that is also listed in dataset A. I created the 'identify' variable to check that only lines from dataset B are in my dataset (dataset_C).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My two datasets are structured as follows:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Dataset_A&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;ID Drug Dose Date Identify&lt;/P&gt;&lt;P&gt;1 a b c 1&lt;/P&gt;&lt;P&gt;3 d e f 1&lt;/P&gt;&lt;P&gt;5 g h e 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Dataset_B&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;ID Drug Dose Date Identify&lt;/P&gt;&lt;P&gt;1 a b c 2&lt;/P&gt;&lt;P&gt;1 c c c&amp;nbsp;2&lt;/P&gt;&lt;P&gt;2 o p q 2&lt;/P&gt;&lt;P&gt;3 d e f 2&lt;/P&gt;&lt;P&gt;3 b b b 2&lt;/P&gt;&lt;P&gt;4 u v w 2&lt;/P&gt;&lt;P&gt;5 g h e 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I used this command:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sort data=dataset A;
by id;
run;

proc sort data=dataset B;
by id;
run;

data dataset_C;
merge dataset_A (in = in1) dataset_B (in = in2);
by id;
if in 1 and in2;
run;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;However:&amp;nbsp;&lt;/STRONG&gt;when I check dataset_C there are no duplicate lines, but some lines have identify=1 and some have identify=2. How can I get it to only overwrite lines from dataset_A. Or is there a better way to program this, without using the merge command?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So what I want to get is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Dataset_C&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;ID Drug Dose Date Identify&lt;/P&gt;&lt;P&gt;1 a b c 2&lt;/P&gt;&lt;P&gt;1 c c c&amp;nbsp;2&lt;/P&gt;&lt;P&gt;3 d e f 2&lt;/P&gt;&lt;P&gt;3 b b b 2&lt;/P&gt;&lt;P&gt;5 g h e 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But what I currently get is this: there are just some random identify=1 inthere (not systematically in all lines from Dataset_A though)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Dataset_C&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;ID Drug Dose Date Identify&lt;/P&gt;&lt;P&gt;1 a b c 1&lt;/P&gt;&lt;P&gt;1 c c c&amp;nbsp;2&lt;/P&gt;&lt;P&gt;3 d e f 2&lt;/P&gt;&lt;P&gt;3 b b b 2&lt;/P&gt;&lt;P&gt;5 g h e 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried using the data set command instead, which didn't work. I also tried dropping all variables except for ID and identify from dataset_A, but that also did not work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks in advance! Julia&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 08:35:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-dataset-dropping-all-lines-of-IDs-which-are-not-listed/m-p/793690#M254411</guid>
      <dc:creator>jspoend</dc:creator>
      <dc:date>2022-02-01T08:35:29Z</dc:date>
    </item>
    <item>
      <title>Your second suggestion works like a charm</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-dataset-dropping-all-lines-of-IDs-which-are-not-listed/m-p/793691#M254421</link>
      <description>&lt;P&gt;Hi Kurt,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much, your second suggetion works like a charm. I was not aware of this command.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for the quick reply and apologies, I did not meant to repost my question. I had some error messages when trying to submit it, which may cause this. I'll try to delete them.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best and thanks so much again, Julia&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 10:27:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-dataset-dropping-all-lines-of-IDs-which-are-not-listed/m-p/793691#M254421</guid>
      <dc:creator>jspoend</dc:creator>
      <dc:date>2022-02-01T10:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dataset dropping all lines of IDs which are not listed in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-dataset-dropping-all-lines-of-IDs-which-are-not-listed/m-p/793692#M254413</link>
      <description>&lt;P&gt;Since you only need ID for your check, make sure that only this variable is read:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;merge
  dataset_A (
    in = in1
    keep = id
  )
  dataset_B (
    in = in2
  )
;
if in1 and in2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;otherwise values from dataset_b will overwrite values from dataset_a.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: moved the KEEP= option to dataset_a.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 08:44:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-dataset-dropping-all-lines-of-IDs-which-are-not-listed/m-p/793692#M254413</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-02-01T08:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dataset dropping all lines of IDs which are not listed in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-dataset-dropping-all-lines-of-IDs-which-are-not-listed/m-p/793696#M254417</link>
      <description>&lt;P&gt;With a (rather) recent addition to the SAS data step tools, you can avoid doing a sort:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dataset_c;
set dataset_b;
if _n_ = 1
then do;
  declare hash a (dataset:"dataset_a");
  a.definekey("id");
  a.definedone();
end;
if a.check() = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Feb 2022 08:48:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-dataset-dropping-all-lines-of-IDs-which-are-not-listed/m-p/793696#M254417</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-02-01T08:48:19Z</dc:date>
    </item>
    <item>
      <title>Re: Create dataset of IDs that are listed in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-dataset-dropping-all-lines-of-IDs-which-are-not-listed/m-p/793702#M254422</link>
      <description>&lt;P&gt;Please do not double-post.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 09:09:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-dataset-dropping-all-lines-of-IDs-which-are-not-listed/m-p/793702#M254422</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-02-01T09:09:50Z</dc:date>
    </item>
  </channel>
</rss>

