<?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: Fill missing values with the previous values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/860312#M339868</link>
    <description>&lt;P&gt;In you example data you did not want to write out that observation.&amp;nbsp; The DELETE statement will end the iteration of the data step right there.&amp;nbsp; Since there is no explicit OUTPUT statement there is an implicit OUTPUT done when the step reaches the end of an iteration, so with the DELETE statement that implicit OUTPUT never happens.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your data was different such that you did want to write out that observation then just don't include the DELETE statement.&lt;/P&gt;
&lt;P&gt;A common example would be a report were the first column is used to group the data so it is only present on the first observation in a group.&amp;nbsp; You wouldn't want to delete that first observation.&amp;nbsp; But if you had a report where the group name is on its own line, like your example , then you don't want to include that line.&lt;/P&gt;</description>
    <pubDate>Wed, 22 Feb 2023 21:52:51 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-02-22T21:52:51Z</dc:date>
    <item>
      <title>Fill missing values with the previous values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326233#M72623</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have a dataset that looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 240pt;" width="320" cellspacing="0" cellpadding="0" border="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" width="64" span="5" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt; width: 48pt;" width="64" height="20"&gt;SEX&lt;/TD&gt;
&lt;TD style="width: 48pt;" width="64"&gt;COUNTRY&lt;/TD&gt;
&lt;TD style="width: 48pt;" width="64"&gt;PERIOD&lt;/TD&gt;
&lt;TD style="width: 48pt;" width="64"&gt;X1&lt;/TD&gt;
&lt;TD style="width: 48pt;" width="64"&gt;X2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;MALE&lt;/TD&gt;
&lt;TD&gt;A&lt;/TD&gt;
&lt;TD align="right"&gt;2000&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;FEMALE&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;MALE&lt;/TD&gt;
&lt;TD&gt;B&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;FEMALE&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right"&gt;5&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;MALE&lt;/TD&gt;
&lt;TD&gt;C&lt;/TD&gt;
&lt;TD align="right"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;…&lt;/TD&gt;
&lt;TD&gt;…&lt;/TD&gt;
&lt;TD&gt;…&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;Z&lt;/TD&gt;
&lt;TD align="right"&gt;2050&lt;/TD&gt;
&lt;TD align="right"&gt;6&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to fill the missing value of SEX COUNTRY and PERIOD with the previous value, until it changes. So it should look like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 240pt;" width="320" cellspacing="0" cellpadding="0" border="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" width="64" span="5" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt; width: 48pt;" width="64" height="20"&gt;SEX&lt;/TD&gt;
&lt;TD style="width: 48pt;" width="64"&gt;COUNTRY&lt;/TD&gt;
&lt;TD style="width: 48pt;" width="64"&gt;PERIOD&lt;/TD&gt;
&lt;TD style="width: 48pt;" width="64"&gt;X1&lt;/TD&gt;
&lt;TD style="width: 48pt;" width="64"&gt;X2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;MALE&lt;/TD&gt;
&lt;TD&gt;A&lt;/TD&gt;
&lt;TD align="right"&gt;2000&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;MALE&lt;/TD&gt;
&lt;TD&gt;A&lt;/TD&gt;
&lt;TD align="right"&gt;2000&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;MALE&lt;/TD&gt;
&lt;TD&gt;A&lt;/TD&gt;
&lt;TD align="right"&gt;2000&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;FEMALE&lt;/TD&gt;
&lt;TD&gt;A&lt;/TD&gt;
&lt;TD align="right"&gt;2000&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;FEMALE&lt;/TD&gt;
&lt;TD&gt;A&lt;/TD&gt;
&lt;TD align="right"&gt;2000&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;FEMALE&lt;/TD&gt;
&lt;TD&gt;A&lt;/TD&gt;
&lt;TD align="right"&gt;2000&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;MALE&lt;/TD&gt;
&lt;TD&gt;B&lt;/TD&gt;
&lt;TD align="right"&gt;2000&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;MALE&lt;/TD&gt;
&lt;TD&gt;B&lt;/TD&gt;
&lt;TD align="right"&gt;2000&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;MALE&lt;/TD&gt;
&lt;TD&gt;B&lt;/TD&gt;
&lt;TD align="right"&gt;2000&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;FEMALE&lt;/TD&gt;
&lt;TD&gt;B&lt;/TD&gt;
&lt;TD align="right"&gt;2000&lt;/TD&gt;
&lt;TD align="right"&gt;5&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;FEMALE&lt;/TD&gt;
&lt;TD&gt;B&lt;/TD&gt;
&lt;TD align="right"&gt;2000&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;FEMALE&lt;/TD&gt;
&lt;TD&gt;B&lt;/TD&gt;
&lt;TD align="right"&gt;2000&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;MALE&lt;/TD&gt;
&lt;TD&gt;C&lt;/TD&gt;
&lt;TD align="right"&gt;2000&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;…&lt;/TD&gt;
&lt;TD&gt;…&lt;/TD&gt;
&lt;TD&gt;…&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD style="height: 15.0pt;" height="20"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;Z&lt;/TD&gt;
&lt;TD align="right"&gt;2050&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not really sure how to do this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2017 12:27:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326233#M72623</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2017-01-20T12:27:35Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values with the previous values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326236#M72624</link>
      <description>&lt;P&gt;NVM, I found the solution&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;retain _period;&lt;BR /&gt;if not missing(period) then _period=period;&lt;BR /&gt;else period=_period;&lt;BR /&gt;drop _period;&lt;BR /&gt;&lt;BR /&gt;retain _sex;&lt;BR /&gt;if not missing(sex) then _sex=sex;&lt;BR /&gt;else sex=_sex;&lt;BR /&gt;drop _sex;&lt;BR /&gt;&lt;BR /&gt;retain _country;&lt;BR /&gt;if not missing(country) then _country=country;&lt;BR /&gt;else country=_country;&lt;BR /&gt;drop _country;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2017 12:35:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326236#M72624</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2017-01-20T12:35:13Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values with the previous values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326237#M72625</link>
      <description>&lt;P&gt;You see that you write a piece of code repeatedly. This is a case for using a macro to reduce your work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro process(variable);
retain help_&amp;amp;variable;
if not missing(&amp;amp;variable)
then _&amp;amp;variable = &amp;amp;variable;
else &amp;amp;variable = _&amp;amp;variable;
drop _&amp;amp;variable;
%mend;

data want;
set have;
%process(sex)
%process(country)
%process(period)
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Jan 2017 12:44:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326237#M72625</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-01-20T12:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values with the previous values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326243#M72627</link>
      <description>&lt;P&gt;A more important question would be why the "data" is like that in the first place. &amp;nbsp;It looks a bit like your reading in a produced report - not a recommended approach for multiple reasons (populations, calculations, assumptions etc.). &amp;nbsp;Get the real "data" and use that.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2017 13:06:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326243#M72627</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-20T13:06:02Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values with the previous values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326244#M72628</link>
      <description>&lt;P&gt;Or use an array and loop over the array rather than bit by bit.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2017 13:07:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326244#M72628</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-20T13:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values with the previous values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326245#M72629</link>
      <description>&lt;P&gt;I copied/pasted in Excel the output of a proc tabulate and then imported it in SAS. When I tried the out statement, it gaves me only one column for variables X1 X2. I suppose this was probably not the most efficient way.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2017 13:10:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326245#M72629</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2017-01-20T13:10:27Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values with the previous values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326262#M72630</link>
      <description>&lt;P&gt;No, its really not. &amp;nbsp;Use out= from tabulate, then manipulate the output dataset to get what you want. &amp;nbsp;Alternative, use one of the other procedures (means/summary/SQL aggregates) or one of the other hundreds of ways to get output you want. &amp;nbsp;For example, your output doesn't make any sense to me:&lt;/P&gt;
&lt;TABLE border="0" width="320" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64" height="20"&gt;SEX&lt;/TD&gt;
&lt;TD width="64"&gt;COUNTRY&lt;/TD&gt;
&lt;TD width="64"&gt;PERIOD&lt;/TD&gt;
&lt;TD width="64"&gt;X1&lt;/TD&gt;
&lt;TD width="64"&gt;X2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="20"&gt;MALE&lt;/TD&gt;
&lt;TD&gt;A&lt;/TD&gt;
&lt;TD align="right"&gt;2000&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="20"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="20"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;Why are there three rows, there is no identifer on each row to say what the rows reflect other then the first one?&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2017 13:28:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326262#M72630</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-20T13:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values with the previous values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326263#M72631</link>
      <description>It is the output of a proc tabulate (cels below were merged).</description>
      <pubDate>Fri, 20 Jan 2017 13:30:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326263#M72631</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2017-01-20T13:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values with the previous values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326264#M72632</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/33143"&gt;@Demographer&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I copied/pasted in Excel the output of a proc tabulate and then imported it in SAS. When I tried the out statement, it gaves me only one column for variables X1 X2. I suppose this was probably not the most efficient way.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;PROC TABULATE can create a data set directly using OUT= on the PROC statement.&amp;nbsp;&amp;nbsp; This would avoid all the headaches associates with a trip to EXhell and back.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can more easily fix your data imported from EXhell using the update trick&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data haveV/view=haveV;
   set have;
   retain dummy 1;
   run;
data want;
   update haveV(obs=0 keep=dummy) haveV;
   by dummy;
   output;
   drop dummy;
   run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Jan 2017 13:31:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326264#M72632</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2017-01-20T13:31:26Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values with the previous values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326267#M72633</link>
      <description>I tried this. The problem is that I want 2 separate column for X1 and X2 (these are 2 categories of a same variable). When I used the out= statement, they appear in a single column.</description>
      <pubDate>Fri, 20 Jan 2017 13:33:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326267#M72633</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2017-01-20T13:33:21Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values with the previous values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326268#M72634</link>
      <description>&lt;P&gt;Yes, but it doesn't make much sense. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have a male, from country A in period 2000, who has reulsts 2,3 (no information as to what the 2/3 represents). &amp;nbsp;You then have two more rows 2/2 2/2. &amp;nbsp;Which is it 2/3, 2/2 or 2/2? &amp;nbsp;Or was it three timepoints within period 2000? &amp;nbsp;Post some test data if you want some code on how to do it directly.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2017 13:35:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326268#M72634</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-20T13:35:23Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values with the previous values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326270#M72635</link>
      <description>Don't pay attention to the data. I cannot copy the real values for confidentiality purposes. These are just random values. There is also another row that I forget to include which was the age group.</description>
      <pubDate>Fri, 20 Jan 2017 13:40:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326270#M72635</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2017-01-20T13:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values with the previous values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326271#M72636</link>
      <description>&lt;P&gt;Ok then, at a guess:&lt;/P&gt;
&lt;PRE&gt;proc means data=have;
  by sex country period age_group;
  var thevar;
  where thevar="A";
  output out=tab1 n=x1;
run;
proc means data=have;
  by sex country period age_group;
  var thevar;
  where thevar="B";
  output out=tab2 n=x2;
run;
data want;
  merge tab1 tab2;
  by sex country period age_group;
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;You could also proc means to get your overall output then transpose the data up, or count it directly in a datastep etc.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2017 13:48:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/326271#M72636</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-20T13:48:42Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values with the previous values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/400391#M97070</link>
      <description>Love this!</description>
      <pubDate>Mon, 02 Oct 2017 18:58:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/400391#M97070</guid>
      <dc:creator>MelissaM</dc:creator>
      <dc:date>2017-10-02T18:58:17Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values with the previous values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/543079#M150121</link>
      <description>&lt;P&gt;Hello Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I succeeded to replace missing values by the previous values.&lt;/P&gt;&lt;P&gt;but only on the column "year_2017" .&lt;/P&gt;&lt;P&gt;my dataset has many columns ...&amp;nbsp;year_2013, year_2014,year_2015,.......year_2018.&lt;/P&gt;&lt;P&gt;how could I apply this code below for each column year_xxxx&lt;/P&gt;&lt;P&gt;retain _an_2017 ;&lt;/P&gt;&lt;P&gt;if not missing(an_2017) then _an_2017 = an_2017 ; else an_2017 = _an_2017 ;&lt;/P&gt;&lt;P&gt;drop _an_2017 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks a lot in advance&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;Nasser&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2019 10:19:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/543079#M150121</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2019-03-14T10:19:49Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values with the previous values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/543098#M150122</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/147725"&gt;@Nasser_DRMCP&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello Kurt,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I succeeded to replace missing values by the previous values.&lt;/P&gt;
&lt;P&gt;but only on the column "year_2017" .&lt;/P&gt;
&lt;P&gt;my dataset has many columns ...&amp;nbsp;year_2013, year_2014,year_2015,.......year_2018.&lt;/P&gt;
&lt;P&gt;how could I apply this code below for each column year_xxxx&lt;/P&gt;
&lt;P&gt;retain _an_2017 ;&lt;/P&gt;
&lt;P&gt;if not missing(an_2017) then _an_2017 = an_2017 ; else an_2017 = _an_2017 ;&lt;/P&gt;
&lt;P&gt;drop _an_2017 ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks a lot in advance&lt;/P&gt;
&lt;P&gt;regards&lt;/P&gt;
&lt;P&gt;Nasser&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Erroneous posting in the wrong topic?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2019 11:41:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/543098#M150122</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-14T11:41:18Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values with the previous values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/625959#M184560</link>
      <description>&lt;P&gt;I have the newest version of sas 9.4.&amp;nbsp; I used to use this code but now it only works on the first retain statement.&amp;nbsp; All subsequent retain statements give the error message "&amp;nbsp;&lt;/P&gt;&lt;P&gt;retain _analyst;&lt;BR /&gt;------&lt;BR /&gt;180&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;"&lt;/P&gt;&lt;P&gt;any ideas why this doesn't work now?&lt;/P&gt;&lt;P&gt;I tried retain _ALL_ and this doesn't help.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 19:30:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/625959#M184560</guid>
      <dc:creator>today</dc:creator>
      <dc:date>2020-02-19T19:30:30Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values with the previous values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/625961#M184562</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/312954"&gt;@today&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have the newest version of sas 9.4.&amp;nbsp; I used to use this code but now it only works on the first retain statement.&amp;nbsp; All subsequent retain statements give the error message "&amp;nbsp;&lt;/P&gt;
&lt;P&gt;retain _analyst;&lt;BR /&gt;------&lt;BR /&gt;180&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;"&lt;/P&gt;
&lt;P&gt;any ideas why this doesn't work now?&lt;/P&gt;
&lt;P&gt;I tried retain _ALL_ and this doesn't help.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please open a new thread for your question.&amp;nbsp; Include more lines from the log so that the error message is shown in context.&amp;nbsp; Also use the Insert Code button so that formatting (like what word is underlined) is preserved.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 19:42:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/625961#M184562</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-19T19:42:55Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values with the previous values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/860221#M339844</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;What changes would I make to the DATA step below to get&amp;nbsp; the output&amp;nbsp; appended below?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data test;
infile datalines DSD  missover;
input name:$13. School: $30.;
datalines;
,,Pinecrest Elementary School
Craig Smith, 
Paula Johnson, 
Chung Wang,
;
proc print; run;

data test1;
set test;
retain _school;
if not missing(school) then _school=school;
else school = _school;
drop _school;
run;
proc print data=test1;
run;&lt;/PRE&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;(Desired output, not generated by the above code blocks)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Obs name School&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1 Craig Smith Pinecrest Elementary School&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2 Paula Johnson Pinecrest Elementary School&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;3 Chung Wang Pinecrest Elementary School&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2023 16:40:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/860221#M339844</guid>
      <dc:creator>pkm_edu</dc:creator>
      <dc:date>2023-02-22T16:40:42Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values with the previous values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/860229#M339845</link>
      <description>&lt;P&gt;If you want to fix the first step to generate that output without the need for the second step then this is classic example of reading in a report where some "header" information is not repeated.&amp;nbsp; You just need to read the header information once and remember it. Much like the second step is doing with data coming from a dataset instead of a text file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  infile datalines dsd truncover ;
  length name $13 _school school $30 ;
  retain school;
  input name _school;
  if not missing(_school) then do;
     school=_school;
     delete;
  end;
  drop _school ;
datalines;
,Pinecrest Elementary School
Craig Smith, 
Paula Johnson, 
Chung Wang,
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PS I fixed the first line of data so that it has only TWO values and not the THREE it had it what you posted by removing the extra comma.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2023 17:05:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/m-p/860229#M339845</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-22T17:05:52Z</dc:date>
    </item>
  </channel>
</rss>

