<?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: code to pull forward missing values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/code-to-pull-forward-missing-values/m-p/345770#M79599</link>
    <description>&lt;P&gt;You have two (as I recall) sets of code that being with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; if not missing(Value1)
&lt;/PRE&gt;
&lt;P&gt;A quick change might be something like (untested):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; if first.cat2 or not missing(Value1)
&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
    <pubDate>Thu, 30 Mar 2017 14:40:10 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-03-30T14:40:10Z</dc:date>
    <item>
      <title>code to pull forward missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-to-pull-forward-missing-values/m-p/345753#M79589</link>
      <description>&lt;P&gt;I am using the following code to impute/pull forward missing values:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA WORK.Test;&lt;BR /&gt; INPUT Cat1 $ Cat2 $ RunningNumber Value1 Value2;&lt;BR /&gt; DATALINES;&lt;BR /&gt;Cat1_1 Cat2_1 1 1 2&lt;BR /&gt;Cat1_1 Cat2_1 2 . 3&lt;BR /&gt;Cat1_1 Cat2_1 3 . .&lt;BR /&gt;Cat1_1 Cat2_1 4 2 1&lt;BR /&gt;Cat1_2 Cat2_2 1 3 2&lt;BR /&gt;Cat1_2 Cat2_2 2 . 3&lt;BR /&gt;Cat1_2 Cat2_2 3 2 4&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;/*ensure that things are in the right order*/&lt;BR /&gt;proc sort data = WORK.Test;&lt;BR /&gt; by Cat1 Cat2 RunningNumber;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;DATA WORK.Test;&lt;BR /&gt; SET WORK.Test;&lt;BR /&gt; by Cat1 Cat2;&lt;BR /&gt; &lt;BR /&gt; retain _Temp1;&lt;BR /&gt; if not missing(Value1)&lt;BR /&gt; then &lt;BR /&gt; do&lt;BR /&gt; _Temp1=Value1;&lt;BR /&gt; ImputedValue1=Value1;&lt;BR /&gt; end;&lt;BR /&gt; else &lt;BR /&gt; ImputedValue1=_Temp1;&lt;BR /&gt; drop _Temp1;&lt;BR /&gt;&lt;BR /&gt; retain _Temp2;&lt;BR /&gt; if not missing(Value2)&lt;BR /&gt; then &lt;BR /&gt; do&lt;BR /&gt; _Temp2=Value2;&lt;BR /&gt; ImputedValue2=Value2;&lt;BR /&gt; end;&lt;BR /&gt; else &lt;BR /&gt; ImputedValue2=_Temp2;&lt;BR /&gt; drop _Temp2;&lt;BR /&gt;run; &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Inside each combination of Cat1 and Cat2 missing value should be imputed from the last seen non missing value 1 or 2 ordered by&amp;nbsp;RunningNumber. The current result looks like this and is correct:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cat1 Cat2 RunningNumber Value1 Value2 ImputedValue1 ImputedValue2&lt;BR /&gt;Cat1_1 Cat2_1 1 1 2 1 2&lt;BR /&gt;Cat1_1 Cat2_1 2 . 3 1 3&lt;BR /&gt;Cat1_1 Cat2_1 3 . . 1 3&lt;BR /&gt;Cat1_1 Cat2_1 4 2 1 2 1&lt;BR /&gt;Cat1_2 Cat2_2 1 3 2 3 2&lt;BR /&gt;Cat1_2 Cat2_2 2 . 3 3 3&lt;BR /&gt;Cat1_2 Cat2_2 3 2 4 2 4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you experts please be so kind and review this bit of code. IMHO it is correct. Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2017 14:16:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-to-pull-forward-missing-values/m-p/345753#M79589</guid>
      <dc:creator>csetzkorn</dc:creator>
      <dc:date>2017-03-30T14:16:13Z</dc:date>
    </item>
    <item>
      <title>Re: code to pull forward missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-to-pull-forward-missing-values/m-p/345755#M79591</link>
      <description>&lt;P&gt;Only problem I see is that you don't account for changes in cat1 cat2 thus, if the first running number is missing a value, it will grab it from the previous cat1 cat2 combination.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2017 14:21:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-to-pull-forward-missing-values/m-p/345755#M79591</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-30T14:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: code to pull forward missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-to-pull-forward-missing-values/m-p/345768#M79598</link>
      <description>Thanks - how can I avoid this please? I would have thought that by Cat1 Cat2; takes care of this ...</description>
      <pubDate>Thu, 30 Mar 2017 14:35:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-to-pull-forward-missing-values/m-p/345768#M79598</guid>
      <dc:creator>csetzkorn</dc:creator>
      <dc:date>2017-03-30T14:35:34Z</dc:date>
    </item>
    <item>
      <title>Re: code to pull forward missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-to-pull-forward-missing-values/m-p/345770#M79599</link>
      <description>&lt;P&gt;You have two (as I recall) sets of code that being with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; if not missing(Value1)
&lt;/PRE&gt;
&lt;P&gt;A quick change might be something like (untested):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; if first.cat2 or not missing(Value1)
&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2017 14:40:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-to-pull-forward-missing-values/m-p/345770#M79599</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-30T14:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: code to pull forward missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-to-pull-forward-missing-values/m-p/345821#M79623</link>
      <description>&lt;P&gt;This is more easily done using the UPDATE trick.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.Test;
   INPUT Cat1 $ Cat2 $ RunningNumber Value1 Value2;
   DATALINES;
Cat1_1 Cat2_1 1 1 2
Cat1_1 Cat2_1 2 . 3
Cat1_1 Cat2_1 3 . .
Cat1_1 Cat2_1 4 2 1
Cat1_2 Cat2_2 1 3 2
Cat1_2 Cat2_2 2 . 3
Cat1_2 Cat2_2 3 2 4
;;;;
   run;
proc print;
   run;
data locf;
   update test(obs=0) test;
   by cat1 cat2;
   output;
   run;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG title="Capture.PNG" alt="Capture.PNG" src="https://communities.sas.com/t5/image/serverpage/image-id/8047i09934BF864EF2DE6/image-size/original?v=1.0&amp;amp;px=-1" border="0" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2017 16:48:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-to-pull-forward-missing-values/m-p/345821#M79623</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2017-03-30T16:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: code to pull forward missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-to-pull-forward-missing-values/m-p/345859#M79642</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;: I agree&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;p.s. Are you going to be at SGF?&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2017 17:58:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-to-pull-forward-missing-values/m-p/345859#M79642</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-30T17:58:05Z</dc:date>
    </item>
  </channel>
</rss>

