<?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: Retain Flag Conditionally in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retain-Flag-Conditionally/m-p/304655#M64858</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76394"&gt;@SambitNandi&lt;/a&gt; wrote:&lt;BR /&gt;That is what I need to create.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Did the code not work?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 14 Oct 2016 13:08:05 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-10-14T13:08:05Z</dc:date>
    <item>
      <title>Retain Flag Conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Flag-Conditionally/m-p/304525#M64821</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a flag with the following rules at ID States Level. The Dataset has ID, States, Gap(Between consecutive states) and a condition flag.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Every time the for a given ID the Condition 1 = 1 (This is universally true)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Flag as well inititates as Type1, then if for the next state for an ID the gap is &amp;gt;=180 then flag = Type2, else Type1 reatins to types 2.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For states 3 and above, if the Condition 1 = 1 then reset to type and apply the above rule, else retain earlier flag.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is a sample datset...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ID	States	Gap	Condition 1	Flag
1087013	1	0	1	Type1
1087013	2	180	0	Type2
1087013	3	34	0	Type2
1087013	4	45	1	Type1
1087013	5	77	0	Type1
1103719	1	0	1	Type1
1103719	2	743	0	Type2
1103719	3	20	0	Type2
1103719	4	2	0	Type2
1103719	5	0	1	Type1
1103719	6	50	0	Type1
1103719	7	10	0	Type1
1103719	8	0	0	Type1
1126597	1	0	1	Type1
1126597	2	200	0	Type2
1126597	3	30	0	Type2
1126597	4	0	0	Type2
1293105	1	0	1	Type1
1297440	1	0	1	Type1&lt;/PRE&gt;&lt;P&gt;Any help is appreciated!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in Advance&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2016 04:38:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Flag-Conditionally/m-p/304525#M64821</guid>
      <dc:creator>SambitNandi</dc:creator>
      <dc:date>2016-10-14T04:38:11Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Flag Conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Flag-Conditionally/m-p/304532#M64825</link>
      <description>&lt;P&gt;Retain flag;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if condition=1 then flag = 'Type1';&lt;/P&gt;
&lt;P&gt;else if gap&amp;gt;=180 then flag = 'Type2';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This assumes you DO NOT have a variable named flag in your dataset already.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2016 05:27:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Flag-Conditionally/m-p/304532#M64825</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-14T05:27:48Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Flag Conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Flag-Conditionally/m-p/304610#M64850</link>
      <description>That is what I need to create.</description>
      <pubDate>Fri, 14 Oct 2016 11:18:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Flag-Conditionally/m-p/304610#M64850</guid>
      <dc:creator>SambitNandi</dc:creator>
      <dc:date>2016-10-14T11:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Flag Conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Flag-Conditionally/m-p/304638#M64855</link>
      <description>&lt;P&gt;I think a little more needs to be built into the logic:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by ID;&lt;/P&gt;
&lt;P&gt;if first.ID then flag='Type1';&lt;/P&gt;
&lt;P&gt;else if gap &amp;gt;= 180 then flag='Type2';&lt;/P&gt;
&lt;P&gt;if states &amp;gt;= 3 and condition_1=1 then flag='Type1';&lt;/P&gt;
&lt;P&gt;retain flag;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's not 100% clear whether it is possible to have gap &amp;gt;= 180 for the first observation for a STATE. &amp;nbsp;What should happen in that case?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't test it today, so you'll need to try it to see if it gives you any trouble.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2016 12:26:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Flag-Conditionally/m-p/304638#M64855</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-10-14T12:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Flag Conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Flag-Conditionally/m-p/304655#M64858</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76394"&gt;@SambitNandi&lt;/a&gt; wrote:&lt;BR /&gt;That is what I need to create.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Did the code not work?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2016 13:08:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Flag-Conditionally/m-p/304655#M64858</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-14T13:08:05Z</dc:date>
    </item>
  </channel>
</rss>

