<?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 to replace only the first missing numeric value from a column? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-only-the-first-missing-numeric-value-from-a/m-p/706561#M216867</link>
    <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input a;
datalines;
1
2
6
.
.
.
;

data want;
   set have;
   if a = . &amp;amp; _iorc_ = 0 then do;
      a      = -10;
      _iorc_ = 1;
   end; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;a 
1 
2 
6 
-10 
. 
. &lt;/PRE&gt;</description>
    <pubDate>Thu, 17 Dec 2020 08:17:57 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2020-12-17T08:17:57Z</dc:date>
    <item>
      <title>How to replace only the first missing numeric value from a column?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-only-the-first-missing-numeric-value-from-a/m-p/706560#M216866</link>
      <description>&lt;P&gt;I have a column in a table like this -&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Column A&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Now I only want to replace the first missing value in the column with a numeric value(For ex -10)&lt;/P&gt;
&lt;P&gt;Output&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Column A&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 10&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The code should be dynamic, i.e. It should automatically identify the first missing value and then replace it.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2020 08:13:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-only-the-first-missing-numeric-value-from-a/m-p/706560#M216866</guid>
      <dc:creator>Saurabh_Rana</dc:creator>
      <dc:date>2020-12-17T08:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace only the first missing numeric value from a column?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-only-the-first-missing-numeric-value-from-a/m-p/706561#M216867</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input a;
datalines;
1
2
6
.
.
.
;

data want;
   set have;
   if a = . &amp;amp; _iorc_ = 0 then do;
      a      = -10;
      _iorc_ = 1;
   end; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;a 
1 
2 
6 
-10 
. 
. &lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Dec 2020 08:17:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-only-the-first-missing-numeric-value-from-a/m-p/706561#M216867</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-12-17T08:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace only the first missing numeric value from a column?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-only-the-first-missing-numeric-value-from-a/m-p/706584#M216877</link>
      <description>&lt;P&gt;I would use this construct:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by a notsorted;
  if first.a and missing(a) then
    a=10;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It is easier to understand than manipulating _IORC_, as suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: But it does work differently; it replaces the first of any series of missing values, not just the very first missing value.&lt;/P&gt;
&lt;P&gt;So, with you example data, it gives the same result. But with data like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input a;
datalines;
1
2
6
.
.
.
5
.
.
;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;it gives a different result, as the missing value after 5 is also replaced.&lt;/P&gt;
&lt;P&gt;If you only want the first missing value replaced (not the first in each series), another possibility is to modify the data in place, which is probably the fastest, CPU-wise:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  modify have;
  if missing(a) then do;
    a=10;
    replace;
    stop;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Meaning that you do not read and copy the 3 zillion observations after the first missing value.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2020 11:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-only-the-first-missing-numeric-value-from-a/m-p/706584#M216877</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-12-17T11:03:05Z</dc:date>
    </item>
  </channel>
</rss>

