<?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 blank cells with data till the next filled cell using do loops in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Filling-blank-cells-with-data-till-the-next-filled-cell-using-do/m-p/741367#M231752</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp; Thank you for your assistance much appreciated&lt;/P&gt;</description>
    <pubDate>Fri, 14 May 2021 09:34:08 GMT</pubDate>
    <dc:creator>Ricardo96</dc:creator>
    <dc:date>2021-05-14T09:34:08Z</dc:date>
    <item>
      <title>Filling blank cells with data till the next filled cell using do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-blank-cells-with-data-till-the-next-filled-cell-using-do/m-p/740162#M231147</link>
      <description>&lt;P&gt;How do i write a do while loop to fill the cells with PnP in the Retailer column up until it finds PEP and fill the blank lines after PEP with PEP.&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do i accommodate if there is a larger dataset with a lot of Retailer names that follow this same format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when i write is as:&lt;/P&gt;&lt;P&gt;data R_and_P;&lt;/P&gt;&lt;P&gt;set work.R_and_P;&lt;/P&gt;&lt;P&gt;Do Until(Retailer = "PEP);&lt;/P&gt;&lt;P&gt;if Retailer = " " then retailer = "PnP";&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code goes into an infinite Loop and crashes my machine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your assistance in advance.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="example dataset.PNG" style="width: 224px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59178i7370CE7FD72DE445/image-size/large?v=v2&amp;amp;px=999" role="button" title="example dataset.PNG" alt="example dataset.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 10 May 2021 12:36:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-blank-cells-with-data-till-the-next-filled-cell-using-do/m-p/740162#M231147</guid>
      <dc:creator>Ricardo96</dc:creator>
      <dc:date>2021-05-10T12:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: Filling blank cells with data till the next filled cell using do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-blank-cells-with-data-till-the-next-filled-cell-using-do/m-p/740166#M231149</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/324976"&gt;@Ricardo96&lt;/a&gt;&amp;nbsp;You do not need a loop or any fancy logic. Just retain the non missings across each datastep iteration capturing in a temporary variable and plug in the missings from the non missing temp variable. Simple as that-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
 set your_dataset;
 retain _r;
 length _r $10;/*set this to the length of retailer variable length*/
 if not missing(retailer) then _r=retailer;
 else retailer=_r;
 drop _r;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 May 2021 13:04:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-blank-cells-with-data-till-the-next-filled-cell-using-do/m-p/740166#M231149</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2021-05-10T13:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: Filling blank cells with data till the next filled cell using do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-blank-cells-with-data-till-the-next-filled-cell-using-do/m-p/740183#M231154</link>
      <description>&lt;P&gt;Another way to do this is to use the implied retain of all variables accessed via a SET statement.&amp;nbsp; In the program below the &lt;EM&gt;&lt;STRONG&gt;IF ... then SET&amp;nbsp; ... POINT=&lt;/STRONG&gt;&lt;/EM&gt; statement is the only one that reads in (unrenamed) RETAILER, so that value is retained until then next non-blank _R (renamed from RETAILER):&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 retailer $3.  product :$10.;
datalines;
PNP Coffee
    Biscuits
    Tea
    Milk
    Sugar
PEP Pants
    Shirts
    Hoodies
    Beanies
    Socks
run;
data want (drop=_:);
  set have (rename=(retailer=_r));
  if _r ^=' ' then set have point=_n_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This can be especially useful if you have lots of variable to retain, not just one, because you won't have to make a lot of assignment statements to retrieve the retained values.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This program, however, won't preserve the order of the variables (retailer will be on the far right).&amp;nbsp; But if you want to preserve the original order of variables, just stick in an "&lt;EM&gt;&lt;STRONG&gt;if 0 then set have;&lt;/STRONG&gt;&lt;/EM&gt;" statement prior to the first &lt;EM&gt;&lt;STRONG&gt;set have&lt;/STRONG&gt;&lt;/EM&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 10 May 2021 14:18:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-blank-cells-with-data-till-the-next-filled-cell-using-do/m-p/740183#M231154</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-05-10T14:18:06Z</dc:date>
    </item>
    <item>
      <title>Re: Filling blank cells with data till the next filled cell using do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-blank-cells-with-data-till-the-next-filled-cell-using-do/m-p/740200#M231166</link>
      <description>Hi Mkeintz….you have indicated that your approach can be useful if you have lots of variables to retain. What would need to be added or modified so that other variables with missing entries would be filled in....Thanks</description>
      <pubDate>Mon, 10 May 2021 14:53:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-blank-cells-with-data-till-the-next-filled-cell-using-do/m-p/740200#M231166</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2021-05-10T14:53:50Z</dc:date>
    </item>
    <item>
      <title>Re: Filling blank cells with data till the next filled cell using do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-blank-cells-with-data-till-the-next-filled-cell-using-do/m-p/740239#M231186</link>
      <description>&lt;P&gt;If you had the same data structure, but with dozens of variables all non-missing only in the first record for each non-blank retail value, then you could use the program almost unchanged:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover ;
  input retailer $3.  product :$10.  source :$4.;
datalines;
PNP Coffee     AAA
    Biscuits
    Tea
    Milk
    Sugar
PEP Pants      BBB
    Shirts
    Hoodies
    Beanies
    Socks
run;
data want (drop=_:);
  if 0 then set have;
  set have (rename=(retailer=_r) drop=source);
  if _r ^=' ' then set have 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;</description>
      <pubDate>Mon, 10 May 2021 18:16:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-blank-cells-with-data-till-the-next-filled-cell-using-do/m-p/740239#M231186</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-05-10T18:16:29Z</dc:date>
    </item>
    <item>
      <title>Re: Filling blank cells with data till the next filled cell using do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-blank-cells-with-data-till-the-next-filled-cell-using-do/m-p/741367#M231752</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp; Thank you for your assistance much appreciated&lt;/P&gt;</description>
      <pubDate>Fri, 14 May 2021 09:34:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-blank-cells-with-data-till-the-next-filled-cell-using-do/m-p/741367#M231752</guid>
      <dc:creator>Ricardo96</dc:creator>
      <dc:date>2021-05-14T09:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: Filling blank cells with data till the next filled cell using do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-blank-cells-with-data-till-the-next-filled-cell-using-do/m-p/741369#M231753</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt; Thank you</description>
      <pubDate>Fri, 14 May 2021 09:40:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-blank-cells-with-data-till-the-next-filled-cell-using-do/m-p/741369#M231753</guid>
      <dc:creator>Ricardo96</dc:creator>
      <dc:date>2021-05-14T09:40:42Z</dc:date>
    </item>
  </channel>
</rss>

