<?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: conditional replacing values in a variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/conditional-replacing-values-in-a-variable/m-p/344636#M79214</link>
    <description>&lt;P&gt;Does this question have anything to do with the value of X? Please explain. Or give a bigger example.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;What if the last two values are not zero? What happens then? Please explain. Or give an example.&lt;/P&gt;</description>
    <pubDate>Mon, 27 Mar 2017 14:06:16 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2017-03-27T14:06:16Z</dc:date>
    <item>
      <title>conditional replacing values in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-replacing-values-in-a-variable/m-p/344630#M79211</link>
      <description>&lt;P&gt;hello people,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i've a dataset like bellow.&lt;/P&gt;&lt;P&gt;x &amp;nbsp; &amp;nbsp; &amp;nbsp; y&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;23&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;56&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i want to replace the zero with '.' but there is one thing that i'm worried with.&lt;/P&gt;&lt;P&gt;last three observations in y are zeros. replace last two zeros with '.' , last but two and first values should stay&amp;nbsp;zeros. ie output will look like&lt;/P&gt;&lt;P&gt;x &amp;nbsp; &amp;nbsp; &amp;nbsp; y&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;23&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;56&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 13:58:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-replacing-values-in-a-variable/m-p/344630#M79211</guid>
      <dc:creator>satish123</dc:creator>
      <dc:date>2017-03-27T13:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: conditional replacing values in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-replacing-values-in-a-variable/m-p/344636#M79214</link>
      <description>&lt;P&gt;Does this question have anything to do with the value of X? Please explain. Or give a bigger example.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;What if the last two values are not zero? What happens then? Please explain. Or give an example.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 14:06:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-replacing-values-in-a-variable/m-p/344636#M79214</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-03-27T14:06:16Z</dc:date>
    </item>
    <item>
      <title>Re: conditional replacing values in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-replacing-values-in-a-variable/m-p/344637#M79215</link>
      <description>&lt;P&gt;A solution for the specific case you presented is pretty easy, but what other cases might exist? I assume this needs to be done by the different x values, for one. Also, within an x value, do non zero numbers appear in more than one grouping surrounded by zeros? &amp;nbsp;That is, could you have 0, 0, 1, 2, 3, 0, 0, 0, 0, 1, 2, 3, 0...?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 14:08:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-replacing-values-in-a-variable/m-p/344637#M79215</guid>
      <dc:creator>collinelliot</dc:creator>
      <dc:date>2017-03-27T14:08:32Z</dc:date>
    </item>
    <item>
      <title>Re: conditional replacing values in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-replacing-values-in-a-variable/m-p/344648#M79219</link>
      <description>&lt;P&gt;hello paigemiller and &lt;SPAN&gt;collinelliot&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;there is more data with last observations zeros and non zeros.&lt;/P&gt;&lt;P&gt;example:&lt;/P&gt;&lt;P&gt;x &amp;nbsp; &amp;nbsp;y&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; 0&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; 311&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp;65&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; 102&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp;217&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp;174&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp;18&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; 12&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; 65&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; 77&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; 92&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp;208&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp;226&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; 19&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 ...etc&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;1 has three consecutive zeros and out of those&amp;nbsp;only last two zeros need to replace with '.' . ie&amp;nbsp;values 174 18 0 0 0 will be 174 18 0 . .&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;keep the value zero if its preceeding value is &amp;nbsp;non zero. replace zero with '.'&amp;nbsp;if its preceeding value is zero.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;if zero comes first keep it as zero.&amp;nbsp;zeros in between non zero values should be zeros only.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;o/p&lt;/P&gt;&lt;P&gt;x &amp;nbsp; &amp;nbsp;y&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; 0&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; 311&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp;65&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; 102&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp;217&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp;174&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp;18&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; 12&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; 65&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; 77&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; 92&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp;208&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp;226&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; 19&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;hope you understood.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 14:43:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-replacing-values-in-a-variable/m-p/344648#M79219</guid>
      <dc:creator>satish123</dc:creator>
      <dc:date>2017-03-27T14:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: conditional replacing values in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-replacing-values-in-a-variable/m-p/344652#M79221</link>
      <description>&lt;P&gt;I think this works for the more extended sample you provided. If there are more nuances to the real data, this might need to modified or scrapped altogether for an alternative approach.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x y;
datalines;
1 0
1 311
1 65
1 102
1 217
1 174
1 18
1 0
1 0
1 0
2 0
2 12
2 65
2 77
2 92
2 0
2 208
2 226
2 19
2 0
;


data want;
    set have;
    by x;
    y2 = y;
    if not first.x then do;
        if y = 0 and lag(y) = 0 then y2 = .;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Mar 2017 14:52:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-replacing-values-in-a-variable/m-p/344652#M79221</guid>
      <dc:creator>collinelliot</dc:creator>
      <dc:date>2017-03-27T14:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: conditional replacing values in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-replacing-values-in-a-variable/m-p/344663#M79222</link>
      <description>&lt;P&gt;I think the easiest way to do this would be to reverse the order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data ordered;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;original_order = _n_;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort data=ordered;&lt;/P&gt;
&lt;P&gt;by descending original_order;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then it becomes easier to detect which observations need to change, since you can start at the beginning of each X value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set ordered;&lt;/P&gt;
&lt;P&gt;by x y notsorted;&lt;/P&gt;
&lt;P&gt;if first.x then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if y=0 then change='Y';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; else change = 'N';&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;retain change;&lt;/P&gt;
&lt;P&gt;if change='Y' then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if last.y then change='N';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; else y=.;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop change;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And finally, put it all back in the original order:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=want;&lt;/P&gt;
&lt;P&gt;by original_order;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 15:21:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-replacing-values-in-a-variable/m-p/344663#M79222</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-03-27T15:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: conditional replacing values in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-replacing-values-in-a-variable/m-p/344667#M79224</link>
      <description>&lt;P&gt;thanks every one each reply helped me a lot.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 15:34:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-replacing-values-in-a-variable/m-p/344667#M79224</guid>
      <dc:creator>satish123</dc:creator>
      <dc:date>2017-03-27T15:34:20Z</dc:date>
    </item>
    <item>
      <title>Re: conditional replacing values in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-replacing-values-in-a-variable/m-p/344684#M79231</link>
      <description>&lt;P&gt;I think this has been granted "solution" status prematurely.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It does not do what&amp;nbsp;I believe the OP wants when (1) there are consecutive zero's in the middle of an X&amp;nbsp;series, or (2) when a given X has only two observations, both equal to zero.&amp;nbsp; See the data sample below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 0&lt;/P&gt;
&lt;P&gt;1 311&lt;/P&gt;
&lt;P&gt;1 65&lt;/P&gt;
&lt;P&gt;1 102&lt;/P&gt;
&lt;P&gt;1 217&lt;/P&gt;
&lt;P&gt;1 0&lt;/P&gt;
&lt;P&gt;1 0&lt;/P&gt;
&lt;P&gt;1 0&lt;/P&gt;
&lt;P&gt;1 174&lt;/P&gt;
&lt;P&gt;1 18&lt;/P&gt;
&lt;P&gt;1 0&lt;/P&gt;
&lt;P&gt;1 0&lt;/P&gt;
&lt;P&gt;1 0&lt;/P&gt;
&lt;P&gt;2 0&lt;/P&gt;
&lt;P&gt;2 12&lt;/P&gt;
&lt;P&gt;2 65&lt;/P&gt;
&lt;P&gt;2 77&lt;/P&gt;
&lt;P&gt;2 92&lt;/P&gt;
&lt;P&gt;2 0&lt;/P&gt;
&lt;P&gt;2 208&lt;/P&gt;
&lt;P&gt;2 226&lt;/P&gt;
&lt;P&gt;2 19&lt;/P&gt;
&lt;P&gt;2 0&lt;/P&gt;
&lt;P&gt;3 0&lt;/P&gt;
&lt;P&gt;3 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 16:36:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-replacing-values-in-a-variable/m-p/344684#M79231</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-03-27T16:36:58Z</dc:date>
    </item>
  </channel>
</rss>

