<?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: How do I flag obs 1 and 2 when condition is true in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-flag-obs-1-and-2-when-condition-is-true/m-p/794575#M254789</link>
    <description>&lt;P&gt;Since your first data set looks like the output from proc mean/ summary you may want to go back a step or two and investigate the option COMPLETETYPES on the proc statement.&lt;/P&gt;
&lt;P&gt;That might (since we have no date prior to your Data xx example) create all the levels of the strata variables you are looking to use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From the documentation:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV class="xis-refProc"&gt;
&lt;DIV class="xis-procStatement"&gt;
&lt;DIV class="xis-procStatementSyntax"&gt;
&lt;DIV class="xis-syntaxDescription"&gt;
&lt;DIV class="xis-optionalArgGroup"&gt;
&lt;DIV id="n1terqe3hgwedcn1fvzn3i20lh6o" class="xis-argDescriptionPair"&gt;
&lt;H4 class="xis-argument"&gt;COMPLETETYPES&lt;/H4&gt;
&lt;DIV class="xis-argumentDescription"&gt;
&lt;P class="xis-paraSimple"&gt;creates all possible combinations of class variables even if the combination does not occur in the input data set.&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/2434"&gt;@jakestat&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to create a conditional flag variable count(cnt) for both the first and second observation rows within/or by 'class' criteria if the condition is true. The class criteria is by Region (_rg) State (st) Strata3 (str3).&amp;nbsp; I am collapsing strata level 1&amp;nbsp; into strata level 2 where n&amp;lt;10 of the variable strataY (str3) and creating strataX (str4) such that strata X receives the value of 1 for both strata 1 and strata 2. an this case I am flagging strata 1 and strata 2 both.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;proc summary data=b; class _rg st str3; var i691; output out=xx sum=; run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;data xx looks like this:&amp;nbsp;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Obs _rg st str3 _TYPE_ _FREQ_ i691 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;218 1 6 0 7 1 . &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;219 1 6 1 7 22 167 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;220 1 6 3 7 11 2082 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;221 1 8 0 7 22 . &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;222 1 8 1 7 39 178 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;223 1 8 2 7 20 290 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;224 1 8 3 7 22 1112 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;225 1 8 4 7 21 11538 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;226 1 16 1 7 23 150 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;227 1 16 3 7 19 5543 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;228 1 20 0 7 26 . &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;229 1 20 1 7 32 118 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;230 1 20 2 7 31 471 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;231 1 20 3 7 31 1590 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;232 1 20 4 7 10 4633 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;233 1 30 0 7 3 . &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;234 1 30 1 7 19 82 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;235 1 30 2 7 15 252&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data c;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;set xx; by _rg st str3;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;where _type_=7;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;if first.st then do;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;if first.st and _freq_&amp;lt;10 and str3 ne 0 then do; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;retain cnt; cnt=1; end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;else cnt=.;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;if cnt=1 then str4=1; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;else str4=str3;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;keep _rg st str3 str4 _freq_ cnt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data C print: Notice state 53 didn't get a 1 looks like this:&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Obs _rg st str3 _FREQ_ cnt str&lt;BR /&gt;1 1 6 0 1 . 0&lt;BR /&gt;2 1 6 1 22 . 1&lt;BR /&gt;3 1 6 3 11 . 3&lt;BR /&gt;4 1 8 0 22 . 0&lt;BR /&gt;5 1 8 1 39 . 1&lt;BR /&gt;6 1 8 2 20 . 2&lt;BR /&gt;7 1 8 3 22 . 3&lt;BR /&gt;8 1 8 4 21 . 4&lt;BR /&gt;&lt;BR /&gt;44 1 48 0 1 . 0&lt;BR /&gt;45 1 48 1 124 . 1&lt;BR /&gt;46 1 48 2 45 . 2&lt;BR /&gt;47 1 48 3 24 . 3&lt;BR /&gt;48 1 48 4 10 . 4&lt;BR /&gt;49 1 49 1 13 . 1&lt;BR /&gt;50 1 49 2 10 . 2&lt;BR /&gt;51 1 53 0 6 . 0&lt;BR /&gt;52 1 53 1 9 . 1&lt;BR /&gt;53 1 53 2 14 . 2&lt;BR /&gt;54 1 53 3 11 . 3&lt;BR /&gt;55 1 56 0 3 . 0&lt;BR /&gt;56 1 56 1 13 . 1&lt;BR /&gt;57 1 56 2 16 . 2&lt;BR /&gt;58 1 56 4 13 . 4&lt;BR /&gt;59 1 99 1 4 1 1&lt;BR /&gt;60 1 99 2 10 1 1&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;I assume the problem is that strata level 1 or 0 does not always occur as a first.var condition. Maybe there is a completely different way to solve this. I'm a novice using&amp;nbsp;someone's previously written code.&amp;nbsp;&amp;nbsp;Thank you.&lt;/FONT&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 04 Feb 2022 17:54:59 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-02-04T17:54:59Z</dc:date>
    <item>
      <title>How do I flag obs 1 and 2 when condition is true</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-flag-obs-1-and-2-when-condition-is-true/m-p/794557#M254782</link>
      <description>&lt;P&gt;I am trying to create a conditional flag variable count(cnt) for both the first and second observation rows within/or by 'class' criteria if the condition is true. The class criteria is by Region (_rg) State (st) Strata3 (str3).&amp;nbsp; I am collapsing strata level 1&amp;nbsp; into strata level 2 where n&amp;lt;10 of the variable strataY (str3) and creating strataX (str4) such that strata X receives the value of 1 for both strata 1 and strata 2. an this case I am flagging strata 1 and strata 2 both.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;proc summary data=b; class _rg st str3; var i691; output out=xx sum=; run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;data xx looks like this:&amp;nbsp;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Obs _rg st str3 _TYPE_ _FREQ_ i691 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;218 1 6 0 7 1 . &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;219 1 6 1 7 22 167 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;220 1 6 3 7 11 2082 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;221 1 8 0 7 22 . &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;222 1 8 1 7 39 178 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;223 1 8 2 7 20 290 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;224 1 8 3 7 22 1112 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;225 1 8 4 7 21 11538 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;226 1 16 1 7 23 150 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;227 1 16 3 7 19 5543 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;228 1 20 0 7 26 . &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;229 1 20 1 7 32 118 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;230 1 20 2 7 31 471 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;231 1 20 3 7 31 1590 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;232 1 20 4 7 10 4633 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;233 1 30 0 7 3 . &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;234 1 30 1 7 19 82 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;235 1 30 2 7 15 252&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data c;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;set xx; by _rg st str3;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;where _type_=7;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;if first.st then do;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;if first.st and _freq_&amp;lt;10 and str3 ne 0 then do; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;retain cnt; cnt=1; end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;else cnt=.;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;if cnt=1 then str4=1; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;else str4=str3;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;keep _rg st str3 str4 _freq_ cnt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data C print: Notice state 53 didn't get a 1 looks like this:&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Obs _rg st str3 _FREQ_ cnt str&lt;BR /&gt;1 1 6 0 1 . 0&lt;BR /&gt;2 1 6 1 22 . 1&lt;BR /&gt;3 1 6 3 11 . 3&lt;BR /&gt;4 1 8 0 22 . 0&lt;BR /&gt;5 1 8 1 39 . 1&lt;BR /&gt;6 1 8 2 20 . 2&lt;BR /&gt;7 1 8 3 22 . 3&lt;BR /&gt;8 1 8 4 21 . 4&lt;BR /&gt;&lt;BR /&gt;44 1 48 0 1 . 0&lt;BR /&gt;45 1 48 1 124 . 1&lt;BR /&gt;46 1 48 2 45 . 2&lt;BR /&gt;47 1 48 3 24 . 3&lt;BR /&gt;48 1 48 4 10 . 4&lt;BR /&gt;49 1 49 1 13 . 1&lt;BR /&gt;50 1 49 2 10 . 2&lt;BR /&gt;51 1 53 0 6 . 0&lt;BR /&gt;52 1 53 1 9 . 1&lt;BR /&gt;53 1 53 2 14 . 2&lt;BR /&gt;54 1 53 3 11 . 3&lt;BR /&gt;55 1 56 0 3 . 0&lt;BR /&gt;56 1 56 1 13 . 1&lt;BR /&gt;57 1 56 2 16 . 2&lt;BR /&gt;58 1 56 4 13 . 4&lt;BR /&gt;59 1 99 1 4 1 1&lt;BR /&gt;60 1 99 2 10 1 1&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;I assume the problem is that strata level 1 or 0 does not always occur as a first.var condition. Maybe there is a completely different way to solve this. I'm a novice using&amp;nbsp;someone's previously written code.&amp;nbsp;&amp;nbsp;Thank you.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 16:48:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-flag-obs-1-and-2-when-condition-is-true/m-p/794557#M254782</guid>
      <dc:creator>jakestat</dc:creator>
      <dc:date>2022-02-04T16:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I flag obs 1 and 2 when condition is true</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-flag-obs-1-and-2-when-condition-is-true/m-p/794575#M254789</link>
      <description>&lt;P&gt;Since your first data set looks like the output from proc mean/ summary you may want to go back a step or two and investigate the option COMPLETETYPES on the proc statement.&lt;/P&gt;
&lt;P&gt;That might (since we have no date prior to your Data xx example) create all the levels of the strata variables you are looking to use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From the documentation:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV class="xis-refProc"&gt;
&lt;DIV class="xis-procStatement"&gt;
&lt;DIV class="xis-procStatementSyntax"&gt;
&lt;DIV class="xis-syntaxDescription"&gt;
&lt;DIV class="xis-optionalArgGroup"&gt;
&lt;DIV id="n1terqe3hgwedcn1fvzn3i20lh6o" class="xis-argDescriptionPair"&gt;
&lt;H4 class="xis-argument"&gt;COMPLETETYPES&lt;/H4&gt;
&lt;DIV class="xis-argumentDescription"&gt;
&lt;P class="xis-paraSimple"&gt;creates all possible combinations of class variables even if the combination does not occur in the input data set.&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/2434"&gt;@jakestat&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to create a conditional flag variable count(cnt) for both the first and second observation rows within/or by 'class' criteria if the condition is true. The class criteria is by Region (_rg) State (st) Strata3 (str3).&amp;nbsp; I am collapsing strata level 1&amp;nbsp; into strata level 2 where n&amp;lt;10 of the variable strataY (str3) and creating strataX (str4) such that strata X receives the value of 1 for both strata 1 and strata 2. an this case I am flagging strata 1 and strata 2 both.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;proc summary data=b; class _rg st str3; var i691; output out=xx sum=; run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;data xx looks like this:&amp;nbsp;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Obs _rg st str3 _TYPE_ _FREQ_ i691 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;218 1 6 0 7 1 . &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;219 1 6 1 7 22 167 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;220 1 6 3 7 11 2082 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;221 1 8 0 7 22 . &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;222 1 8 1 7 39 178 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;223 1 8 2 7 20 290 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;224 1 8 3 7 22 1112 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;225 1 8 4 7 21 11538 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;226 1 16 1 7 23 150 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;227 1 16 3 7 19 5543 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;228 1 20 0 7 26 . &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;229 1 20 1 7 32 118 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;230 1 20 2 7 31 471 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;231 1 20 3 7 31 1590 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;232 1 20 4 7 10 4633 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;233 1 30 0 7 3 . &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;234 1 30 1 7 19 82 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;235 1 30 2 7 15 252&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data c;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;set xx; by _rg st str3;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;where _type_=7;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;if first.st then do;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;if first.st and _freq_&amp;lt;10 and str3 ne 0 then do; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;retain cnt; cnt=1; end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;else cnt=.;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;if cnt=1 then str4=1; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;else str4=str3;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;keep _rg st str3 str4 _freq_ cnt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data C print: Notice state 53 didn't get a 1 looks like this:&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Obs _rg st str3 _FREQ_ cnt str&lt;BR /&gt;1 1 6 0 1 . 0&lt;BR /&gt;2 1 6 1 22 . 1&lt;BR /&gt;3 1 6 3 11 . 3&lt;BR /&gt;4 1 8 0 22 . 0&lt;BR /&gt;5 1 8 1 39 . 1&lt;BR /&gt;6 1 8 2 20 . 2&lt;BR /&gt;7 1 8 3 22 . 3&lt;BR /&gt;8 1 8 4 21 . 4&lt;BR /&gt;&lt;BR /&gt;44 1 48 0 1 . 0&lt;BR /&gt;45 1 48 1 124 . 1&lt;BR /&gt;46 1 48 2 45 . 2&lt;BR /&gt;47 1 48 3 24 . 3&lt;BR /&gt;48 1 48 4 10 . 4&lt;BR /&gt;49 1 49 1 13 . 1&lt;BR /&gt;50 1 49 2 10 . 2&lt;BR /&gt;51 1 53 0 6 . 0&lt;BR /&gt;52 1 53 1 9 . 1&lt;BR /&gt;53 1 53 2 14 . 2&lt;BR /&gt;54 1 53 3 11 . 3&lt;BR /&gt;55 1 56 0 3 . 0&lt;BR /&gt;56 1 56 1 13 . 1&lt;BR /&gt;57 1 56 2 16 . 2&lt;BR /&gt;58 1 56 4 13 . 4&lt;BR /&gt;59 1 99 1 4 1 1&lt;BR /&gt;60 1 99 2 10 1 1&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;I assume the problem is that strata level 1 or 0 does not always occur as a first.var condition. Maybe there is a completely different way to solve this. I'm a novice using&amp;nbsp;someone's previously written code.&amp;nbsp;&amp;nbsp;Thank you.&lt;/FONT&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 17:54:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-flag-obs-1-and-2-when-condition-is-true/m-p/794575#M254789</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-02-04T17:54:59Z</dc:date>
    </item>
  </channel>
</rss>

