<?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: Identify first occurrence based on different keys in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Identify-first-occurrence-based-on-different-keys/m-p/932906#M366959</link>
    <description>&lt;P&gt;It seems sort of obvious that if you have multiple variables (???) then perhaps combine them or set the value of a single variable to 1,2,3 and 4 then sort the data by your identification variables and that new variable.&lt;/P&gt;
&lt;P&gt;I would think first. logic would then make sense. (If this were my data knowing this was a later step I might of set that "order of priority" or whatever at each stage when combining the data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But no example data provided so can't be sure.&lt;/P&gt;</description>
    <pubDate>Tue, 18 Jun 2024 21:14:30 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2024-06-18T21:14:30Z</dc:date>
    <item>
      <title>Identify first occurrence based on different keys</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-first-occurrence-based-on-different-keys/m-p/932905#M366958</link>
      <description>&lt;P&gt;I had to match two files based on 4 different keys from most strict to loose to add a cost variable. I did this in steps using proc sql and created 4 different tables. Then I appended the tables together with the non-matches so that I had the table I started with but with match_flag1, match_flag2, match_flag3, match_flag4.&amp;nbsp; I only want to count the first occurrence of the data that I retrieved from the other table based on the hierarchy of best match.&amp;nbsp; I can't figure out how to do this and keep the original data. I feel like Hash Add() could do this if I output to 4 different tables and add them together again but I need to keep all the data in place so that duplicated reasoning can be maintained for each row. In other words I cannot output a separate table. I just want to update the value if it is the first occurrence of the match.&amp;nbsp; For example, if match_flag3=1 for one row of the key and match_flag4=1 for a diffferent row, I only want to keep the value in the row where match_flag3 =1 for that key. I tried doing this with first. and last. logic but becuase there are 4 different types of matches I could not get the right sort and logic.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following logic almost gets me there but there could still be duplicates keys when match_flag# variables =1 so I need to still identify the first occurrence of the key&amp;nbsp; within the following logic.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;data test;&lt;/DIV&gt;&lt;DIV&gt;if _N_ = 1 then do;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;declare hash m1 (dataset: "Have");&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;m1.defineKey("id", "dos", "diag", "provider", "lob");&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;m1.defineData("match_flag1");&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;m1.defineDone();&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;declare hash m2 (dataset: "Have");&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;m2.defineKey("id", "dos", "diag", "provider");&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;m2.defineData("match_flag2");&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;m2.defineDone();&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;declare hash m3 (dataset: "Have");&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;m3.defineKey("id", "dos", "diag", "lob");&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;m3.defineData("match_flag3");&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;m3.defineDone();&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;declare hash m4 (dataset: "Have");&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;m4.defineKey("id", "dos", "diag");&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;m4.defineData("match_flag4");&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;m4.defineDone();&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;end;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;set &lt;SPAN&gt;Have&amp;nbsp;&lt;/SPAN&gt;(drop=match_flag1 match_flag2 match_flag3 match_flag4 );&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;length match_flag1 8. match_flag2 8. match_flag3 8. match_flag4 8.;&lt;/DIV&gt;&lt;DIV&gt;if m1.find() = 0 then do;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;value_revised =value;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;match_keep=1;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;else if m2.find()=0 then do;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;value_revised = value;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;match_keep=1;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;else if m3.find()=0 then do;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;value_revised=value;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;match_keep=1;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;else if m4.find()=0 then do;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;value_revised =value;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;match_keep=1;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;else do;&lt;/DIV&gt;&lt;DIV&gt;match_keep= 0;&lt;/DIV&gt;&lt;DIV&gt;value_revised = 0;&lt;/DIV&gt;&lt;DIV&gt;end;&lt;/DIV&gt;&lt;DIV&gt;;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2024 20:43:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-first-occurrence-based-on-different-keys/m-p/932905#M366958</guid>
      <dc:creator>CP2</dc:creator>
      <dc:date>2024-06-18T20:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: Identify first occurrence based on different keys</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-first-occurrence-based-on-different-keys/m-p/932906#M366959</link>
      <description>&lt;P&gt;It seems sort of obvious that if you have multiple variables (???) then perhaps combine them or set the value of a single variable to 1,2,3 and 4 then sort the data by your identification variables and that new variable.&lt;/P&gt;
&lt;P&gt;I would think first. logic would then make sense. (If this were my data knowing this was a later step I might of set that "order of priority" or whatever at each stage when combining the data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But no example data provided so can't be sure.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2024 21:14:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-first-occurrence-based-on-different-keys/m-p/932906#M366959</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-06-18T21:14:30Z</dc:date>
    </item>
    <item>
      <title>Re: Identify first occurrence based on different keys</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-first-occurrence-based-on-different-keys/m-p/932907#M366960</link>
      <description>&lt;P&gt;I for one, need sample data in the form of a working data step, and also showing what the result should look like.&amp;nbsp; The sample data preferably would have an instance of the problem of duplicates you are trying to manage.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Question:&amp;nbsp; are data items in the hash objects expected to satisfy a match more than once?&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2024 21:37:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-first-occurrence-based-on-different-keys/m-p/932907#M366960</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-06-18T21:37:03Z</dc:date>
    </item>
  </channel>
</rss>

