<?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 Impute Missing Valu in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Impute-Missing-Valu/m-p/409067#M67147</link>
    <description>&lt;P&gt;My data is in this format:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input GROUP1 GROUP2 GROUP3 VAR1 VAR2;
cards;
A A1 A11 10 12
A A1 A11 13 .
A A1 A12 15 16
A A2 A12 . 17
A A2 A13 12 12
A A2 A13 19 18
B B1 B11 15 21
B B1 B11 22 29
B B1 B12 31 40
B B2 B12 . .
B B2 B13 5 3
B B2 B13 . .
;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And I want the result in this format:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data desired;
input GROUP1 GROUP2 GROUP3 VAR1 VAR2;
cards;
A A1 A11 10 12
A A1 A11 13 12
A A1 A12 15 16
A A2 A12 15 17
A A2 A13 12 12
A A2 A13 19 18
B B1 B11 15 21
B B1 B11 22 29
B B1 B12 31 40
B B2 B12 31 31
B B2 B13 5 3
B B2 B13 5 3
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;I want to impute the missing values by replicating the previous value from the same above group. E.g. for group combinations (B, B2, B13), there's a missing value for variable "Value2". This value will be replicated with 20, which is the above value from the same group.&lt;BR /&gt; I tried to follow this option. But this does not have multiple value computation option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data imputedData;
set mydata;
n=_n_;
if missing(Value1) then
do;
do until (not missing(value1));
n=n-1;
set mydata(keep=Value1) point=n; *second SET statement;
end;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But the problem is it can calculate only 1 variable at a time. And also it was taking a long time to compute. My dataset is around 400K number of rows.&lt;BR /&gt; &lt;BR /&gt;If someone please guide me how to do it.&lt;BR /&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 31 Oct 2017 12:49:36 GMT</pubDate>
    <dc:creator>newbie_ari</dc:creator>
    <dc:date>2017-10-31T12:49:36Z</dc:date>
    <item>
      <title>Impute Missing Valu</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Impute-Missing-Valu/m-p/409067#M67147</link>
      <description>&lt;P&gt;My data is in this format:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input GROUP1 GROUP2 GROUP3 VAR1 VAR2;
cards;
A A1 A11 10 12
A A1 A11 13 .
A A1 A12 15 16
A A2 A12 . 17
A A2 A13 12 12
A A2 A13 19 18
B B1 B11 15 21
B B1 B11 22 29
B B1 B12 31 40
B B2 B12 . .
B B2 B13 5 3
B B2 B13 . .
;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And I want the result in this format:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data desired;
input GROUP1 GROUP2 GROUP3 VAR1 VAR2;
cards;
A A1 A11 10 12
A A1 A11 13 12
A A1 A12 15 16
A A2 A12 15 17
A A2 A13 12 12
A A2 A13 19 18
B B1 B11 15 21
B B1 B11 22 29
B B1 B12 31 40
B B2 B12 31 31
B B2 B13 5 3
B B2 B13 5 3
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;I want to impute the missing values by replicating the previous value from the same above group. E.g. for group combinations (B, B2, B13), there's a missing value for variable "Value2". This value will be replicated with 20, which is the above value from the same group.&lt;BR /&gt; I tried to follow this option. But this does not have multiple value computation option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data imputedData;
set mydata;
n=_n_;
if missing(Value1) then
do;
do until (not missing(value1));
n=n-1;
set mydata(keep=Value1) point=n; *second SET statement;
end;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But the problem is it can calculate only 1 variable at a time. And also it was taking a long time to compute. My dataset is around 400K number of rows.&lt;BR /&gt; &lt;BR /&gt;If someone please guide me how to do it.&lt;BR /&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2017 12:49:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Impute-Missing-Valu/m-p/409067#M67147</guid>
      <dc:creator>newbie_ari</dc:creator>
      <dc:date>2017-10-31T12:49:36Z</dc:date>
    </item>
    <item>
      <title>Re: Impute Missing Valu</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Impute-Missing-Valu/m-p/409086#M67149</link>
      <description>&lt;P&gt;Please post test data in the form of a datastep - use the {i} to post code!&amp;nbsp; This is so we can run the datastep and have soe data to write code on, not here to type in test data or try to read unformatted text.&amp;nbsp; Also post example of what you want out.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2017 12:39:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Impute-Missing-Valu/m-p/409086#M67149</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-10-31T12:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: Impute Missing Valu</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Impute-Missing-Valu/m-p/409088#M67150</link>
      <description>&lt;PRE&gt;

data have;
input Var1 $ Var2 $ Var3 $ Value1 Imputer_Value1 Value2 Imputer_Value2;
cards;
A A1 A11 6 6 15 15
A A1 A11 9 9 14 14
A A1 A12 1 1 19 19
A A2 A12 1 16 16
A A2 A13 10 10 13 13
A A2 A13 4 4 . 13
B B1 B11 8 8 13 13
B B1 B11 9 9 17 17
B B1 B12 5 5 18 18
B B2 B12 . 5 12 12
B B2 B13 2 2 20 20
B B2 B13 1 1 . 20
;
run;
data want;
 update have(obs=0) have;
 by var1 var2 var3;
 output;
run;
&amp;lt;.pre&amp;gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Oct 2017 12:43:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Impute-Missing-Valu/m-p/409088#M67150</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-10-31T12:43:05Z</dc:date>
    </item>
    <item>
      <title>Re: Impute Missing Valu</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Impute-Missing-Valu/m-p/409102#M67151</link>
      <description>&lt;P&gt;This is a good approach.&amp;nbsp; It fills in for all variables, and&amp;nbsp; you don't even need to know the variable names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking at your data on lines 3 and 4, it looks like you want to fill in values within GROUP1 regardless of whether GROUP2 or GROUP3 changes.&amp;nbsp; So your BY statement might be shorter:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;by group1;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2017 13:37:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Impute-Missing-Valu/m-p/409102#M67151</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-10-31T13:37:35Z</dc:date>
    </item>
    <item>
      <title>Re: Impute Missing Valu</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Impute-Missing-Valu/m-p/409256#M67162</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;: I didn't get your answer. My lowest level is Group3.  So you are saying I should use by statement in my code? The code I used works fine for small dataset. But the dataset of my size it's takes over 3 hours. Also, it calculates value I variable at a time. So the entire process is extremely time consuming. Is there any other alternative?</description>
      <pubDate>Tue, 31 Oct 2017 18:12:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Impute-Missing-Valu/m-p/409256#M67162</guid>
      <dc:creator>newbie_ari</dc:creator>
      <dc:date>2017-10-31T18:12:51Z</dc:date>
    </item>
    <item>
      <title>Re: Impute Missing Valu</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Impute-Missing-Valu/m-p/409258#M67163</link>
      <description>&lt;P&gt;Sorry, when I said "good approach" I was talking about KSharp's solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The question I was trying to address is this.&amp;nbsp; When should the previous value be carried forward?&amp;nbsp; When GROUP1 changes from "A" to "B", is it still OK to carry a value forward from an "A" observation to a "B" observation?&amp;nbsp; (I suspect the answer is no.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How about when GROUP1 remains "A", but GROUP2 changes from "A1" to "A2"?&amp;nbsp; Is it permissible to carry forward a value from "A1" to "A2" observations?&amp;nbsp; I suspect the answer is yes, because in your original example you do exactly that.&amp;nbsp; (Refer to lines 3 and 4 of the data.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if my suspected answers are correct, and if your data is already sorted as indicated, the program becomes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data ImputedData;&lt;/P&gt;
&lt;P&gt;update mydata (obs=0) mydata;&lt;/P&gt;
&lt;P&gt;by group1;&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2017 18:25:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Impute-Missing-Valu/m-p/409258#M67163</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-10-31T18:25:19Z</dc:date>
    </item>
    <item>
      <title>Re: Impute Missing Valu</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Impute-Missing-Valu/m-p/411112#M67333</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;: Thanks for the clarification!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2017 10:28:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Impute-Missing-Valu/m-p/411112#M67333</guid>
      <dc:creator>newbie_ari</dc:creator>
      <dc:date>2017-11-07T10:28:48Z</dc:date>
    </item>
  </channel>
</rss>

