<?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 create flag for duplicate data by consideration of intermediate occurrence of same data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/create-flag-for-duplicate-data-by-consideration-of-intermediate/m-p/622655#M183176</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Help me on this below scenario.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;output requirements&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1)flag variable-&amp;nbsp; Flag on Countries IND and CHN.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If country&lt;STRONG&gt; IND&lt;/STRONG&gt; then for first occurrence its should flag as &lt;STRONG&gt;1&lt;/STRONG&gt; and if same data available in next occurrence&amp;nbsp; that should flag it as &lt;STRONG&gt;0&amp;nbsp;&lt;/STRONG&gt; .&amp;nbsp;&lt;/P&gt;&lt;P&gt;If same data chain got dis continued then again if we find IND in country column again it flags first data occurrence as&lt;STRONG&gt; 1&lt;/STRONG&gt; and remain &lt;STRONG&gt;0.&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Similarly&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If country &lt;STRONG&gt;CHN&lt;/STRONG&gt; then for first occurrence its should flag as &lt;STRONG&gt;0&lt;/STRONG&gt; , if same data available in next occurrence&amp;nbsp; that should flag it as&lt;STRONG&gt; 0&lt;/STRONG&gt;&amp;nbsp; and only flag &lt;STRONG&gt;1&lt;/STRONG&gt; for last occurrence of &lt;STRONG&gt;CHN&lt;/STRONG&gt; before dis continue the same data .&lt;/P&gt;&lt;P&gt;If same data chain got dis continued then again if we find CHN in country column again it flags first data occurrence as 0 and next occurrence 1 &lt;STRONG&gt;.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2)Count variable-&amp;nbsp; cumulative count .&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Country&lt;/P&gt;&lt;P&gt;IND&lt;/P&gt;&lt;P&gt;IND&lt;/P&gt;&lt;P&gt;ENG&lt;/P&gt;&lt;P&gt;CHN&lt;/P&gt;&lt;P&gt;CHN&lt;/P&gt;&lt;P&gt;CHN&lt;/P&gt;&lt;P&gt;IND&lt;/P&gt;&lt;P&gt;IND&lt;/P&gt;&lt;P&gt;IND&lt;/P&gt;&lt;P&gt;USA&lt;/P&gt;&lt;P&gt;PAK&lt;/P&gt;&lt;P&gt;CHN&lt;/P&gt;&lt;P&gt;CHN&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Expected output&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;count Country FLAG&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; IND&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; IND&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ENG&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CHN&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CHN&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CHN&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; IND&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IND&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IND&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; USA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PAK&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CHN&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CHN&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;</description>
    <pubDate>Thu, 06 Feb 2020 10:45:12 GMT</pubDate>
    <dc:creator>Veeresh</dc:creator>
    <dc:date>2020-02-06T10:45:12Z</dc:date>
    <item>
      <title>create flag for duplicate data by consideration of intermediate occurrence of same data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-flag-for-duplicate-data-by-consideration-of-intermediate/m-p/622655#M183176</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Help me on this below scenario.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;output requirements&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1)flag variable-&amp;nbsp; Flag on Countries IND and CHN.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If country&lt;STRONG&gt; IND&lt;/STRONG&gt; then for first occurrence its should flag as &lt;STRONG&gt;1&lt;/STRONG&gt; and if same data available in next occurrence&amp;nbsp; that should flag it as &lt;STRONG&gt;0&amp;nbsp;&lt;/STRONG&gt; .&amp;nbsp;&lt;/P&gt;&lt;P&gt;If same data chain got dis continued then again if we find IND in country column again it flags first data occurrence as&lt;STRONG&gt; 1&lt;/STRONG&gt; and remain &lt;STRONG&gt;0.&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Similarly&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If country &lt;STRONG&gt;CHN&lt;/STRONG&gt; then for first occurrence its should flag as &lt;STRONG&gt;0&lt;/STRONG&gt; , if same data available in next occurrence&amp;nbsp; that should flag it as&lt;STRONG&gt; 0&lt;/STRONG&gt;&amp;nbsp; and only flag &lt;STRONG&gt;1&lt;/STRONG&gt; for last occurrence of &lt;STRONG&gt;CHN&lt;/STRONG&gt; before dis continue the same data .&lt;/P&gt;&lt;P&gt;If same data chain got dis continued then again if we find CHN in country column again it flags first data occurrence as 0 and next occurrence 1 &lt;STRONG&gt;.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2)Count variable-&amp;nbsp; cumulative count .&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Country&lt;/P&gt;&lt;P&gt;IND&lt;/P&gt;&lt;P&gt;IND&lt;/P&gt;&lt;P&gt;ENG&lt;/P&gt;&lt;P&gt;CHN&lt;/P&gt;&lt;P&gt;CHN&lt;/P&gt;&lt;P&gt;CHN&lt;/P&gt;&lt;P&gt;IND&lt;/P&gt;&lt;P&gt;IND&lt;/P&gt;&lt;P&gt;IND&lt;/P&gt;&lt;P&gt;USA&lt;/P&gt;&lt;P&gt;PAK&lt;/P&gt;&lt;P&gt;CHN&lt;/P&gt;&lt;P&gt;CHN&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Expected output&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;count Country FLAG&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; IND&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; IND&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ENG&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CHN&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CHN&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CHN&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; IND&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IND&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IND&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; USA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PAK&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CHN&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CHN&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;</description>
      <pubDate>Thu, 06 Feb 2020 10:45:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-flag-for-duplicate-data-by-consideration-of-intermediate/m-p/622655#M183176</guid>
      <dc:creator>Veeresh</dc:creator>
      <dc:date>2020-02-06T10:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: create flag for duplicate data by consideration of intermediate occurrence of same data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-flag-for-duplicate-data-by-consideration-of-intermediate/m-p/622658#M183177</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/310458"&gt;@Veeresh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a way to do that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input Country $;
	datalines;
IND
IND
ENG
CHN
CHN
CHN
IND
IND
IND
USA
PAK
CHN
CHN
;

data want;
	set have;
	by country notsorted;
	
	if 		first.country and country = 'IND' then flag = 1;
	else if last.country and country = 'CHN' then flag = 1;
	else 	flag = 0;

	if first.country then count+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Feb 2020 10:52:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-flag-for-duplicate-data-by-consideration-of-intermediate/m-p/622658#M183177</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-06T10:52:57Z</dc:date>
    </item>
  </channel>
</rss>

