<?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: Adding flag column when condition is met in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159707#M263221</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear &lt;A __default_attr="5068" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;, thank you so much for your help!!&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 28 Sep 2014 17:14:45 GMT</pubDate>
    <dc:creator>mark_ph</dc:creator>
    <dc:date>2014-09-28T17:14:45Z</dc:date>
    <item>
      <title>Adding flag column when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159696#M263210</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have dataset &lt;STRONG&gt;db1&lt;/STRONG&gt; including variables: id, start_date, end_date, and V1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;data db1;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;input id&amp;nbsp;&amp;nbsp;&amp;nbsp; start_date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG style="font-size: 10pt; font-style: inherit; background-color: #ffffff; font-family: inherit; font-weight: inherit;"&gt;end_date&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; V1&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;datalines;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130126&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG style="font-family: inherit; font-style: inherit; background-color: #ffffff;"&gt;20130814&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 19&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2013&lt;/STRONG&gt;&lt;/SPAN&gt;0729&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG style="font-family: inherit; font-style: inherit; background-color: #ffffff;"&gt;20130829&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 77&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2013&lt;/STRONG&gt;&lt;/SPAN&gt;0201&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG style="font-family: inherit; font-style: inherit; background-color: #ffffff;"&gt;20130401&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 14&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;103&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2013&lt;/STRONG&gt;&lt;/SPAN&gt;0217&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG style="font-family: inherit; font-style: inherit; background-color: #ffffff;"&gt;20130225&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;104&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2013&lt;/STRONG&gt;&lt;/SPAN&gt;0102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG style="font-family: inherit; font-style: inherit; background-color: #ffffff;"&gt;20131119&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 47&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;I also have dataset &lt;STRONG&gt;db2&lt;/STRONG&gt; including variables: id, date, and V2.&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG style="font-family: inherit; font-style: inherit; font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;data db2;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;input id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; V2&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;datalines;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130719&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 26&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;103&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2013&lt;/STRONG&gt;&lt;/SPAN&gt;0224&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 55&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;105&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2013&lt;/STRONG&gt;&lt;/SPAN&gt;1107&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG style="font-family: inherit; font-size: 10pt; font-style: inherit;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;I would like to create a variable &lt;STRONG&gt;FLAG&lt;/STRONG&gt; in the dataset &lt;STRONG&gt;db1&lt;/STRONG&gt; such that &lt;STRONG&gt;FLAG = 1&lt;/STRONG&gt; if &lt;STRONG&gt;db1.id = db2.id and db2.date &amp;gt;= db1.start_date and db2.date &amp;lt;= db1.end_date&lt;/STRONG&gt;. That is, I would like to obtain the following&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG style="font-family: inherit; font-size: 10pt; font-style: inherit;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;data want;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;input id&amp;nbsp;&amp;nbsp;&amp;nbsp; start_date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG style="font-size: 10pt; font-style: inherit; background-color: #ffffff; font-family: inherit; font-weight: inherit;"&gt;end_date&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; V1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; flag&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;datalines;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130126&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG style="font-family: inherit; font-style: inherit; background-color: #ffffff;"&gt;20130814&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 19&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2013&lt;/STRONG&gt;&lt;/SPAN&gt;0729&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG style="font-family: inherit; font-style: inherit; background-color: #ffffff;"&gt;20130829&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 77&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2013&lt;/STRONG&gt;&lt;/SPAN&gt;0201&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG style="font-family: inherit; font-style: inherit; background-color: #ffffff;"&gt;20130401&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 14&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;103&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2013&lt;/STRONG&gt;&lt;/SPAN&gt;0217&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG style="font-family: inherit; font-style: inherit; background-color: #ffffff;"&gt;20130225&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;104&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2013&lt;/STRONG&gt;&lt;/SPAN&gt;0102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG style="font-family: inherit; font-style: inherit; background-color: #ffffff;"&gt;20131119&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 47&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG style="font-family: inherit; font-style: inherit; font-size: 10pt;"&gt;;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;My attempt involves PROC SQL and I'm able to isolate the desired records. However, I'm not able to attach a flag in the original dataset &lt;STRONG&gt;db1&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG style="font-family: inherit; font-size: 10pt; font-style: inherit;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; create table want&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; as select db1.*&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; from db1, db2&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; where db1.id = db2.id and db2.date &amp;gt;= db1.start_date and db2.date &amp;lt;= db2.end_date;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Any help would be highly appreciated.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Sep 2014 13:43:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159696#M263210</guid>
      <dc:creator>mark_ph</dc:creator>
      <dc:date>2014-09-25T13:43:26Z</dc:date>
    </item>
    <item>
      <title>Re: Adding flag column when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159697#M263211</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt; create table want as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select *, case exists (select * from db2 where id=a.id and date between a.start_date and a.end_date) when 1 then 1 else . end as flag &lt;/P&gt;&lt;P&gt;&amp;nbsp; from db1 a&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Sep 2014 13:52:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159697#M263211</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2014-09-25T13:52:02Z</dc:date>
    </item>
    <item>
      <title>Re: Adding flag column when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159698#M263212</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table WANT as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DB1.*,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case when DB2.ID is not null then 1 else . end as FLAG&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DB1 DB1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; left join&amp;nbsp;&amp;nbsp; DB1 DB2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DB1.ID=DB2.ID&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DB1.START_DATE &amp;lt;= DB2.DATE &amp;lt;= DB1.END_DATE;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Sep 2014 13:52:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159698#M263212</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-09-25T13:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: Adding flag column when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159699#M263213</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select db1.*,case when db2.date &amp;gt;= db1.start_date and db2.date &amp;lt;= db1.end_date then 1&lt;/P&gt;&lt;P&gt;end as flag&lt;/P&gt;&lt;P&gt;&amp;nbsp; from db1 left join db2&lt;/P&gt;&lt;P&gt;&amp;nbsp; on db1.id = db2.id;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Sep 2014 13:53:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159699#M263213</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-09-25T13:53:59Z</dc:date>
    </item>
    <item>
      <title>Re: Adding flag column when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159700#M263214</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A __default_attr="4063" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt;, &lt;A __default_attr="814511" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt;, @stat@sas, thank you for your replies.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was wondering whether it is possible to gain a bit in efficiency because my dataset db1 has &amp;gt;30M records and db2 around 0.3 M. It's going to take days in this way (still running...)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Maybe knowing db1 is sorted on id and date and db2 is sorted on id and start_date, SAS could stop checking the condition for remaining records in db2 when db2.id &amp;gt; db1.id.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Sep 2014 12:01:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159700#M263214</guid>
      <dc:creator>mark_ph</dc:creator>
      <dc:date>2014-09-26T12:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: Adding flag column when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159701#M263215</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not thinking of an easy way.&amp;nbsp; Whichever way you look at it your going to have to join the two datasets at some point.&amp;nbsp; There are many tips and tricks on here to speed up things, e.g. break your 30m records down into smaller datasets (maybe on id or something).&amp;nbsp; You can use indexes, get distinct list of ids which match and only do the check on those etc.&amp;nbsp; However at the end of the 30m records is going to take a while regardless.&amp;nbsp; Maybe also evaluate if adding a flag to the big dataset is the best way forward. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Sep 2014 12:20:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159701#M263215</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-09-26T12:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: Adding flag column when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159702#M263216</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table want&lt;/P&gt;&lt;P&gt;&amp;nbsp; as select db1.*, &lt;/P&gt;&lt;P&gt;&amp;nbsp; case &lt;/P&gt;&lt;P&gt;&amp;nbsp; when db1.id = db2.id and db2.date &amp;gt;= db1.start_date and db2.date &amp;lt;= db1.end_date then 1&lt;/P&gt;&lt;P&gt;&amp;nbsp; else .&lt;/P&gt;&lt;P&gt;&amp;nbsp; end as flag&lt;/P&gt;&lt;P&gt;&amp;nbsp; from db1 left join db2 on db1.id = db2.id;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Sep 2014 12:46:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159702#M263216</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2014-09-26T12:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: Adding flag column when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159703#M263217</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;1)Hash Table




data db1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input id&amp;nbsp;&amp;nbsp;&amp;nbsp; start_date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end_date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; V1;
datalines;
101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130126&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130814&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 19&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130729&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130829&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 77
102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130201&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130401&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 14
103&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130217&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130225&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11
104&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20131119&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 47
;
data db2;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; V2;
datalines;
101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130719&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 26&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
103&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130224&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 55
105&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20131107&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10
;
run;

data want;
 if _n_ = 1 then do;
 if 0 then set db2;
 declare hash ha(dataset:'db2',hashexp:20);
 ha.definekey('id');
 ha.definedata('date');
 ha.definedone();
end;
set db1;
if ha.find()=0 then flag=ifn( start_date le date le end_date,1,. );
run;











2)Or if dataset have already been sorted , Merge statement 




data w;
 merge db1(in=ina) db2;
 by id;
flag=ifn( start_date le date le end_date,1,. );
if ina;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: xia keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Sep 2014 13:23:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159703#M263217</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-09-26T13:23:24Z</dc:date>
    </item>
    <item>
      <title>Re: Adding flag column when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159704#M263218</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If 'id' in db2 is unique, and both tables are presorted by 'id', then the following will give you a boost on efficiency:&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; db1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; id&amp;nbsp;&amp;nbsp;&amp;nbsp; start_date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end_date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; V1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;datalines&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130126&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130814&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 19 &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130729&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130829&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 77&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130201&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130401&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 14&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;103&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130217&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130225&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;104&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20131119&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 47&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; db2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; V2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;datalines&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130719&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 26 &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;103&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130224&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 55&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;105&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20131107&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;merge&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; db1 db2(&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;drop&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;=v2);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;by&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; id;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; START_DATE &amp;lt;= DATE &amp;lt;= END_DATE &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;then&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; flag=&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;Well, if 'id' is not unique in db2, then we may need to resort to Hash object. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;Good Luck, &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;Haikuo &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Sep 2014 13:33:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159704#M263218</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2014-09-26T13:33:10Z</dc:date>
    </item>
    <item>
      <title>Re: Adding flag column when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159705#M263219</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear &lt;A __default_attr="645292" __jive_macro_name="user" class="jive_macro jive_macro_user" href="https://communities.sas.com/"&gt;&lt;/A&gt;, your solutions are super fast and efficient. Thank you for your precious help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;May I ask you one more thing? My dataset &lt;STRONG&gt;db2&lt;/STRONG&gt; doesn't have unique &lt;STRONG&gt;id&lt;/STRONG&gt; as in the toy example. That is, suppose I have the following (just added the 2nd row of db2, so that db2 doesn't have unique &lt;STRONG&gt;id&lt;/STRONG&gt;s now):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data db1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input id&amp;nbsp;&amp;nbsp;&amp;nbsp; start_date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end_date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; V1;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130126&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130814&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 19&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130729&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130829&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 77&lt;/P&gt;&lt;P&gt;102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130201&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130401&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 14&lt;/P&gt;&lt;P&gt;103&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130217&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130225&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11&lt;/P&gt;&lt;P&gt;104&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20131119&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 47&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data db2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; V2;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130719&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 26&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130730&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 31&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;103&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130224&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 55&lt;/P&gt;&lt;P&gt;105&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20131107&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the result I get right now: the flag is correctly assigned to the 1st record of db1, but not to the 2nd row of db1. That is,&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 10pt; font-style: inherit; font-family: inherit; font-weight: inherit;"&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;data want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;input id&amp;nbsp;&amp;nbsp;&amp;nbsp; start_date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;end_date&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; V1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; flag&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;datalines;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130126&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130814&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 19&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: inherit;"&gt;&lt;STRONG&gt;&lt;SPAN style="font-style: inherit; font-family: inherit;"&gt;101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2013&lt;/SPAN&gt;0729&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130829&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 77&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2013&lt;/SPAN&gt;0201&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130401&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 14&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;103&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2013&lt;/SPAN&gt;0217&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130225&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;104&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2013&lt;/SPAN&gt;0102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20131119&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 47&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;I would like to obtain the following:&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;data want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;input id&amp;nbsp;&amp;nbsp;&amp;nbsp; start_date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;end_date&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; V1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; flag&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;datalines;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130126&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130814&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 19&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: inherit;"&gt;&lt;STRONG&gt;&lt;SPAN style="font-style: inherit; font-family: inherit;"&gt;101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2013&lt;/SPAN&gt;0729&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130829&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 77&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2013&lt;/SPAN&gt;0201&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130401&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 14&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;103&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2013&lt;/SPAN&gt;0217&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130225&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;104&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2013&lt;/SPAN&gt;0102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20131119&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 47&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Please note the flag 1 in the second row this time.&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Thank you for your help.&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 28 Sep 2014 14:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159705#M263219</guid>
      <dc:creator>mark_ph</dc:creator>
      <dc:date>2014-09-28T14:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Adding flag column when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159706#M263220</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A little tweak on &lt;A __default_attr="645292" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt;'s code should do:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt; if _n_ = 1 then do;&lt;/P&gt;&lt;P&gt; if 0 then set db2;&lt;/P&gt;&lt;P&gt; declare hash ha(dataset:'db2',hashexp:20, multidata:'y');&lt;/P&gt;&lt;P&gt; ha.definekey('id');&lt;/P&gt;&lt;P&gt; ha.definedata('date');&lt;/P&gt;&lt;P&gt; ha.definedone();&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;set db1;&lt;/P&gt;&lt;P&gt;rc=ha.find();&lt;/P&gt;&lt;P&gt;if rc ne 0 then flag=.;&lt;/P&gt;&lt;P&gt;else&lt;/P&gt;&lt;P&gt;do&amp;nbsp; while (rc=0);&lt;/P&gt;&lt;P&gt;flag=ifn( start_date le date le end_date,1,flag);&lt;/P&gt;&lt;P&gt;rc=ha.find_next();&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;drop rc;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 28 Sep 2014 16:25:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159706#M263220</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2014-09-28T16:25:49Z</dc:date>
    </item>
    <item>
      <title>Re: Adding flag column when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159707#M263221</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear &lt;A __default_attr="5068" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;, thank you so much for your help!!&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 28 Sep 2014 17:14:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159707#M263221</guid>
      <dc:creator>mark_ph</dc:creator>
      <dc:date>2014-09-28T17:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Adding flag column when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159708#M263222</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mark,&lt;/P&gt;&lt;P&gt;HaiKuo has already done it for me .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data db1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input id&amp;nbsp;&amp;nbsp;&amp;nbsp; start_date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end_date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; V1;
datalines;
101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130126&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130814&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 19&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130729&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130829&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 77
102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130201&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130401&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 14
103&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130217&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130225&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11
104&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20131119&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 47
;
data db2;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; V2;
datalines;
101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130719&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 26
101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130730&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 31
103&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20130224&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 55
105&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20131107&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10
;
run;

data want;
 if _n_ = 1 then do;
 if 0 then set db2;
 declare hash ha(dataset:'db2',hashexp:20,multidata:'y');
 ha.definekey('id');
 ha.definedata('date');
 ha.definedone();
end;
set db1;
rc=ha.find();
do while(rc=0);
&amp;nbsp; if start_date le date le end_date then flag=1;
&amp;nbsp; rc=ha.find_next();
end;
run;



&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Sep 2014 12:08:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159708#M263222</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-09-29T12:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: Adding flag column when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159709#M263223</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you guys for all your help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Sep 2014 12:12:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-flag-column-when-condition-is-met/m-p/159709#M263223</guid>
      <dc:creator>mark_ph</dc:creator>
      <dc:date>2014-09-29T12:12:01Z</dc:date>
    </item>
  </channel>
</rss>

