<?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: Filling up missing rows with previous rows value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-rows-with-previous-rows-value/m-p/530142#M144948</link>
    <description>&lt;P&gt;If&lt;/P&gt;
&lt;OL style="list-style-position: inside;"&gt;
&lt;LI&gt;&amp;nbsp;You have lots of variables that could be missing, not just 2 or 3, making the RETAIN statement approach tedious.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;Those variables are always missing simultaneously.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;then you could take advantage of the SET with POINT= statement, and the DROP and RENAME parameters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an example using a dataset HAVE&amp;nbsp;from SASHELP.CLASS in which each obs is completely written once, and then written 3 times with missing values SEX, WEIGHT, and HEIGHT.&amp;nbsp; Those latter records need the data to be carried forward from the non-missing collection.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  set sashelp.class;
  output;
  call missing(sex, weight,height);
  do copy=1 to 3; output; end;
run;

data want (drop=_sex);
  set have (drop=weight height  rename=(sex=_sex));
  if _sex^=' ' then set have (keep=sex height weight) point=_n_;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL style="list-style-position: inside;"&gt;
&lt;LI&gt;&amp;nbsp;The SET HAVE statement reads in all the variables except the variables in question.&amp;nbsp; But it does read in and renames one of those variables (sex renamed to _sex).&amp;nbsp; The provide a single data point to determine whether all the variables-of-interest are missing.&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;The "IF ... THEN SET" statement only occurs when the variables-of-interest are actually present.&amp;nbsp; Because they are read by a SET statement they are automatically retained (and therefore output) until the next non-missing collection is encountered.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Note the DATA WANT step only takes 4 lines, no matter how many variables are "variables-of-interest".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I repeat, this is for cases in which you know those variables are synchronized in there missing value occurances.&amp;nbsp; Of course you could break this approach down if&amp;nbsp;you had, say, 2 distinct collections of such variables.&lt;/P&gt;</description>
    <pubDate>Fri, 25 Jan 2019 18:14:17 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2019-01-25T18:14:17Z</dc:date>
    <item>
      <title>Filling up missing rows with previous rows value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-rows-with-previous-rows-value/m-p/530048#M144917</link>
      <description>&lt;P&gt;I have an excel file with data looking like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2019-01-25 at 9.22.40 pm.png" style="width: 332px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/26578i7E16D96AC2DE964D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2019-01-25 at 9.22.40 pm.png" alt="Screen Shot 2019-01-25 at 9.22.40 pm.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data shows the company and it's operating locations.&lt;/P&gt;&lt;P&gt;How do I fill in those rows with missing Company and Profit with the previous values but if it hits a row with non-missing Company and Profit then it stops?&lt;/P&gt;&lt;P&gt;i.e. rows 3 to 8 should be Company='Microsoft' and Profit=1000&lt;/P&gt;&lt;P&gt;row 10 should be Company='Apple' and Profit=2000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jan 2019 13:27:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-rows-with-previous-rows-value/m-p/530048#M144917</guid>
      <dc:creator>jungjein</dc:creator>
      <dc:date>2019-01-25T13:27:29Z</dc:date>
    </item>
    <item>
      <title>Re: Filling up missing rows with previous rows value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-rows-with-previous-rows-value/m-p/530050#M144919</link>
      <description>&lt;P&gt;Use retained variables:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
retain _company _profit;
if company ne ''
then _company = company;
else company = _company;
if profit ne .
then _profit = profit;
else profit = _profit;
drop _company _profit;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Jan 2019 13:32:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-rows-with-previous-rows-value/m-p/530050#M144919</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-01-25T13:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: Filling up missing rows with previous rows value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-rows-with-previous-rows-value/m-p/530063#M144928</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
informat Company $20.Profit 8. Location $20.;
input Company $ Profit Location;
infile datalines dlm=',' dsd missover;
datalines;
Microsoft,1000,United States
,,India
,,Hong Kong
,,United Kingdom
,,Ireland
,,Korea
,,Japan
Apple,2000,United States
,,China
Alphabet,20,United States
,,Netherlands
,,Ireland
,,China
Samsung,3,Korea
,,Japan
,,China
;

data temp;
   set have;
   if not missing(Company) then group+1;
run;

data want(drop=group);
   update temp(obs=0) temp;
   by group;
   output;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Jan 2019 13:54:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-rows-with-previous-rows-value/m-p/530063#M144928</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-25T13:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: Filling up missing rows with previous rows value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-rows-with-previous-rows-value/m-p/530068#M144929</link>
      <description>&lt;P&gt;If your pattern holds true in all cases, the group creation and update will work shown by draycut and so will mine. But if your pattern differs, the best "controlled approach" by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp; is probably the safest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just to start my morning with some hash fun, here you go-&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
informat Company $20.Profit 8. Location $20.;
input Company $ Profit Location;
infile datalines dlm=',' dsd missover;
datalines;
Microsoft,1000,United States
,,India
,,Hong Kong
,,United Kingdom
,,Ireland
,,Korea
,,Japan
Apple,2000,United States
,,China
Alphabet,20,United States
,,Netherlands
,,Ireland
,,China
Samsung,3,Korea
,,Japan
,,China
;

data want;
if _n_=1 then do;
   dcl hash H () ;
   h.definekey  ("_iorc_") ;
   h.definedata ("company", "profit") ;
   h.definedone () ;
   end;
set have;
if not missing(company) and not missing(profit) then do;
_iorc_+1;
h.add();
end;
else h.find();
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp; for creating the data have sample.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jan 2019 14:10:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-rows-with-previous-rows-value/m-p/530068#M144929</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-25T14:10:19Z</dc:date>
    </item>
    <item>
      <title>Re: Filling up missing rows with previous rows value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-rows-with-previous-rows-value/m-p/530142#M144948</link>
      <description>&lt;P&gt;If&lt;/P&gt;
&lt;OL style="list-style-position: inside;"&gt;
&lt;LI&gt;&amp;nbsp;You have lots of variables that could be missing, not just 2 or 3, making the RETAIN statement approach tedious.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;Those variables are always missing simultaneously.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;then you could take advantage of the SET with POINT= statement, and the DROP and RENAME parameters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an example using a dataset HAVE&amp;nbsp;from SASHELP.CLASS in which each obs is completely written once, and then written 3 times with missing values SEX, WEIGHT, and HEIGHT.&amp;nbsp; Those latter records need the data to be carried forward from the non-missing collection.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  set sashelp.class;
  output;
  call missing(sex, weight,height);
  do copy=1 to 3; output; end;
run;

data want (drop=_sex);
  set have (drop=weight height  rename=(sex=_sex));
  if _sex^=' ' then set have (keep=sex height weight) point=_n_;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL style="list-style-position: inside;"&gt;
&lt;LI&gt;&amp;nbsp;The SET HAVE statement reads in all the variables except the variables in question.&amp;nbsp; But it does read in and renames one of those variables (sex renamed to _sex).&amp;nbsp; The provide a single data point to determine whether all the variables-of-interest are missing.&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;The "IF ... THEN SET" statement only occurs when the variables-of-interest are actually present.&amp;nbsp; Because they are read by a SET statement they are automatically retained (and therefore output) until the next non-missing collection is encountered.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Note the DATA WANT step only takes 4 lines, no matter how many variables are "variables-of-interest".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I repeat, this is for cases in which you know those variables are synchronized in there missing value occurances.&amp;nbsp; Of course you could break this approach down if&amp;nbsp;you had, say, 2 distinct collections of such variables.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jan 2019 18:14:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-rows-with-previous-rows-value/m-p/530142#M144948</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-01-25T18:14:17Z</dc:date>
    </item>
    <item>
      <title>Re: Filling up missing rows with previous rows value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-rows-with-previous-rows-value/m-p/582848#M165852</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;BR /&gt;Please Can you tell me what's the solution if the missing was before ?&lt;BR /&gt;If I want to fill the missing from the next row&lt;/P&gt;&lt;P&gt;---------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2019 13:07:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-rows-with-previous-rows-value/m-p/582848#M165852</guid>
      <dc:creator>Ali_Ouda</dc:creator>
      <dc:date>2019-08-22T13:07:05Z</dc:date>
    </item>
    <item>
      <title>Re: Filling up missing rows with previous rows value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-rows-with-previous-rows-value/m-p/582884#M165864</link>
      <description>&lt;P&gt;The simplest solution is to reverse sort the dataset, apply the logic, and then sort it back to the original order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&lt;EM&gt;Edit: changed "log" to "logic".&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2019 07:06:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-rows-with-previous-rows-value/m-p/582884#M165864</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-22T07:06:52Z</dc:date>
    </item>
    <item>
      <title>Re: Filling up missing rows with previous rows value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-rows-with-previous-rows-value/m-p/583036#M165931</link>
      <description>Thank you very much.&lt;BR /&gt;</description>
      <pubDate>Thu, 22 Aug 2019 01:05:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-rows-with-previous-rows-value/m-p/583036#M165931</guid>
      <dc:creator>Ali_Ouda</dc:creator>
      <dc:date>2019-08-22T01:05:29Z</dc:date>
    </item>
  </channel>
</rss>

