<?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 How do I write to a new variable based off a match from two datasets? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-write-to-a-new-variable-based-off-a-match-from-two/m-p/697267#M25363</link>
    <description>&lt;P&gt;I have four original datasets:&lt;/P&gt;&lt;P&gt;Dataset A, B, C, D&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also have a final dataset that combines various elements from those four that I'll call FinalDataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is a variable in all four original datasets and my FinalDataset that is called NPI.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to write to a new variable in my FinalDataset called "NPIfound" if the NPI value in the FinalDataset is also found in one of the original datasets.&lt;/P&gt;&lt;P&gt;In other words, If datasetA.NPI = finaldataset.NPI, then output the value "datasetA" to NPIfound.&lt;/P&gt;&lt;P&gt;If that same NPI value is also found in datasetB then I want it to add to NPIfound so that it says "datasetA, datasetB" in the FinalDataset.&lt;/P&gt;</description>
    <pubDate>Fri, 06 Nov 2020 22:51:04 GMT</pubDate>
    <dc:creator>InspectahDex</dc:creator>
    <dc:date>2020-11-06T22:51:04Z</dc:date>
    <item>
      <title>How do I write to a new variable based off a match from two datasets?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-write-to-a-new-variable-based-off-a-match-from-two/m-p/697267#M25363</link>
      <description>&lt;P&gt;I have four original datasets:&lt;/P&gt;&lt;P&gt;Dataset A, B, C, D&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also have a final dataset that combines various elements from those four that I'll call FinalDataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is a variable in all four original datasets and my FinalDataset that is called NPI.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to write to a new variable in my FinalDataset called "NPIfound" if the NPI value in the FinalDataset is also found in one of the original datasets.&lt;/P&gt;&lt;P&gt;In other words, If datasetA.NPI = finaldataset.NPI, then output the value "datasetA" to NPIfound.&lt;/P&gt;&lt;P&gt;If that same NPI value is also found in datasetB then I want it to add to NPIfound so that it says "datasetA, datasetB" in the FinalDataset.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2020 22:51:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-write-to-a-new-variable-based-off-a-match-from-two/m-p/697267#M25363</guid>
      <dc:creator>InspectahDex</dc:creator>
      <dc:date>2020-11-06T22:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write to a new variable based off a match from two datasets?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-write-to-a-new-variable-based-off-a-match-from-two/m-p/697270#M25364</link>
      <description>Did you merge the data sets together using a data step merge or a different method? If you used a merge it's trivial to add that in using the IN option.</description>
      <pubDate>Fri, 06 Nov 2020 23:09:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-write-to-a-new-variable-based-off-a-match-from-two/m-p/697270#M25364</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-11-06T23:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write to a new variable based off a match from two datasets?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-write-to-a-new-variable-based-off-a-match-from-two/m-p/697271#M25365</link>
      <description>&lt;P&gt;I merged the datasets together using a data step merge. Why is it trivial to add that variable in using a IN option? Sorry, I'm new.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2020 23:21:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-write-to-a-new-variable-based-off-a-match-from-two/m-p/697271#M25365</guid>
      <dc:creator>InspectahDex</dc:creator>
      <dc:date>2020-11-06T23:21:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write to a new variable based off a match from two datasets?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-write-to-a-new-variable-based-off-a-match-from-two/m-p/697280#M25368</link>
      <description>&lt;P&gt;Here's a simple way.&amp;nbsp; Assuming all your data sets are already sorted by NPI:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data FinalDataset;
   merge a (in=from_a) b (in=from_b) c (in=from_c) d (in=from_d);
   by NPI;
   NPIfound = cats(from_a, from_b, from_c, from_d);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;By choosing the simple route, you don't get exactly what you asked for.&amp;nbsp; Instead,&amp;nbsp; you get a series of 0's and 1's.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1010 represents found in A, not found in B, found in C, not found in D.&lt;/P&gt;
&lt;P&gt;0001 represents found in D only.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Adding to the complexity by adjusting the program is again relatively easy, but this version might be easier to work with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Learning about MERGE and in= variables is a basic tool you will use often.&amp;nbsp; It is worth the time to learn.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Nov 2020 03:10:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-write-to-a-new-variable-based-off-a-match-from-two/m-p/697280#M25368</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-11-07T03:10:01Z</dc:date>
    </item>
  </channel>
</rss>

