<?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 Array for replacing missing data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885092#M349706</link>
    <description>&lt;P&gt;I have a long data set with 6 years of data for every state. There are 7 variables that have missing data. I want to replace data by state and year where if a variable is missing for a year, replace it with the average of the data value for the year directly above and below, else replace it with data from the nearest year. I have been working on this array for a long time and cannot make it work - with this code I am receiving the following error:&amp;nbsp;ERROR: Array subscript out of range at line 2276 column 49.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data new;&lt;BR /&gt;set old;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Set missing values to the average of the previous and next years */&lt;BR /&gt;array indicators[7] indicator1 indicator2 indicator3 indicator4 indicator5 indicator6 indicator7;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Handle missing values for the first year separately */&lt;BR /&gt;by state year;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if first.state then do;&lt;BR /&gt;do i = 1 to dim(indicators);&lt;BR /&gt;if missing(indicators[i]) and not missing(indicators[i+1]) then&lt;BR /&gt;indicators[i] = indicators[i+1];&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;/* Handle missing values for the last year separately */&lt;BR /&gt;if last.state then do;&lt;BR /&gt;do i = 1 to dim(indicators);&lt;BR /&gt;if missing(indicators[i]) and not missing(indicators[i-1]) then&lt;BR /&gt;indicators[i] = indicators[i-1];&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;/*&lt;BR /&gt;/* Handle missing values for the intermediate years */&lt;BR /&gt;if not first.state and not last.state then do;&lt;BR /&gt;do i = 1 to dim(indicators);&lt;BR /&gt;if missing(indicators[i]) then do;&lt;BR /&gt;/* Calculate the average of the previous and next years */&lt;BR /&gt;if not missing(indicators[i-1]) and not missing(indicators[i+1]) then&lt;BR /&gt;indicators[i] = (indicators[i-1] + indicators[i+1]) / 2;&lt;BR /&gt;/* Look for the closest non-missing year */&lt;BR /&gt;else if not missing(indicators[i-1]) then&lt;BR /&gt;indicators[i] = indicators[i-1];&lt;BR /&gt;else if not missing(indicators[i+1]) then&lt;BR /&gt;indicators[i] = indicators[i+1];&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;drop i;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be GREATLY appreciated!&lt;/P&gt;</description>
    <pubDate>Mon, 17 Jul 2023 15:52:24 GMT</pubDate>
    <dc:creator>EpiMoby</dc:creator>
    <dc:date>2023-07-17T15:52:24Z</dc:date>
    <item>
      <title>Array for replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885092#M349706</link>
      <description>&lt;P&gt;I have a long data set with 6 years of data for every state. There are 7 variables that have missing data. I want to replace data by state and year where if a variable is missing for a year, replace it with the average of the data value for the year directly above and below, else replace it with data from the nearest year. I have been working on this array for a long time and cannot make it work - with this code I am receiving the following error:&amp;nbsp;ERROR: Array subscript out of range at line 2276 column 49.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data new;&lt;BR /&gt;set old;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Set missing values to the average of the previous and next years */&lt;BR /&gt;array indicators[7] indicator1 indicator2 indicator3 indicator4 indicator5 indicator6 indicator7;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Handle missing values for the first year separately */&lt;BR /&gt;by state year;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if first.state then do;&lt;BR /&gt;do i = 1 to dim(indicators);&lt;BR /&gt;if missing(indicators[i]) and not missing(indicators[i+1]) then&lt;BR /&gt;indicators[i] = indicators[i+1];&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;/* Handle missing values for the last year separately */&lt;BR /&gt;if last.state then do;&lt;BR /&gt;do i = 1 to dim(indicators);&lt;BR /&gt;if missing(indicators[i]) and not missing(indicators[i-1]) then&lt;BR /&gt;indicators[i] = indicators[i-1];&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;/*&lt;BR /&gt;/* Handle missing values for the intermediate years */&lt;BR /&gt;if not first.state and not last.state then do;&lt;BR /&gt;do i = 1 to dim(indicators);&lt;BR /&gt;if missing(indicators[i]) then do;&lt;BR /&gt;/* Calculate the average of the previous and next years */&lt;BR /&gt;if not missing(indicators[i-1]) and not missing(indicators[i+1]) then&lt;BR /&gt;indicators[i] = (indicators[i-1] + indicators[i+1]) / 2;&lt;BR /&gt;/* Look for the closest non-missing year */&lt;BR /&gt;else if not missing(indicators[i-1]) then&lt;BR /&gt;indicators[i] = indicators[i-1];&lt;BR /&gt;else if not missing(indicators[i+1]) then&lt;BR /&gt;indicators[i] = indicators[i+1];&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;drop i;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be GREATLY appreciated!&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2023 15:52:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885092#M349706</guid>
      <dc:creator>EpiMoby</dc:creator>
      <dc:date>2023-07-17T15:52:24Z</dc:date>
    </item>
    <item>
      <title>Re: Array for replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885093#M349707</link>
      <description>&lt;P&gt;Whenever there are errors in the log, please show us the &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;ENTIRE&lt;/STRONG&gt; &lt;/FONT&gt;log for the data step (or PROC) that has the error. We don't know what line 2276 is without the log. Please copy the log as text, click on the &amp;lt;/&amp;gt; icon and paste it into the window that appears.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PaigeMiller_0-1663012019648.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75161i0E71B1489A6C9839/image-size/large?v=v2&amp;amp;px=999" role="button" title="PaigeMiller_0-1663012019648.png" alt="PaigeMiller_0-1663012019648.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would also help if you show us a portion of the actual data, following these &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt;&amp;nbsp;and not via any other method.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2023 16:08:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885093#M349707</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-17T16:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: Array for replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885095#M349709</link>
      <description>&lt;P&gt;Please share which bits of your code you believe are getting the value from the previous year's data? And the following?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am asking because I see nothing in the posted code looking "above" or "below".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want anything resembling a working solution you likely will need to provide some example data in the form of data step code so that we can actually see what you are working with. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;/&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/441521"&gt;@EpiMoby&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a long data set with 6 years of data for every state. There are 7 variables that have missing data. I want to replace data by state and year where if a variable is missing for a year, replace it with the average of the data value for the year directly above and below, else replace it with data from the nearest year. I have been working on this array for a long time and cannot make it work - with this code I am receiving the following error:&amp;nbsp;ERROR: Array subscript out of range at line 2276 column 49.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data new;&lt;BR /&gt;set old;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* Set missing values to the average of the previous and next years */&lt;BR /&gt;array indicators[7] indicator1 indicator2 indicator3 indicator4 indicator5 indicator6 indicator7;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* Handle missing values for the first year separately */&lt;BR /&gt;by state year;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if first.state then do;&lt;BR /&gt;do i = 1 to dim(indicators);&lt;BR /&gt;if missing(indicators[i]) and not missing(indicators[i+1]) then&lt;BR /&gt;indicators[i] = indicators[i+1];&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;/* Handle missing values for the last year separately */&lt;BR /&gt;if last.state then do;&lt;BR /&gt;do i = 1 to dim(indicators);&lt;BR /&gt;if missing(indicators[i]) and not missing(indicators[i-1]) then&lt;BR /&gt;indicators[i] = indicators[i-1];&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;/*&lt;BR /&gt;/* Handle missing values for the intermediate years */&lt;BR /&gt;if not first.state and not last.state then do;&lt;BR /&gt;do i = 1 to dim(indicators);&lt;BR /&gt;if missing(indicators[i]) then do;&lt;BR /&gt;/* Calculate the average of the previous and next years */&lt;BR /&gt;if not missing(indicators[i-1]) and not missing(indicators[i+1]) then&lt;BR /&gt;indicators[i] = (indicators[i-1] + indicators[i+1]) / 2;&lt;BR /&gt;/* Look for the closest non-missing year */&lt;BR /&gt;else if not missing(indicators[i-1]) then&lt;BR /&gt;indicators[i] = indicators[i-1];&lt;BR /&gt;else if not missing(indicators[i+1]) then&lt;BR /&gt;indicators[i] = indicators[i+1];&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;drop i;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would be GREATLY appreciated!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2023 16:38:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885095#M349709</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-07-17T16:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: Array for replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885097#M349711</link>
      <description>I don't think arrays are the correct approach here. Arrays are used for working along a single row technically or you can cross rows, but looking forward is difficult. &lt;BR /&gt;&lt;BR /&gt;Assuming you have SAS ETS, using PROC EXPAND with interpolate is the best option. You say the 'nearest' time point, does it matter if it's before or after? What if there's a tie for before/after?&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/etsug/etsug_expand_gettingstarted04.htm#:~:text=To%20interpolate%20missing%20values%20in%20variables%20observed%20at%20specific%20points,time%20values%20for%20the%20observations" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/etsug/etsug_expand_gettingstarted04.htm#:~:text=To%20interpolate%20missing%20values%20in%20variables%20observed%20at%20specific%20points,time%20values%20for%20the%20observations&lt;/A&gt;.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 17 Jul 2023 16:49:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885097#M349711</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-07-17T16:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: Array for replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885106#M349712</link>
      <description>&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Year&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;State&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Variable 1&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Variable 2&lt;/TD&gt;&lt;TD&gt;Variable 3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2014&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0.2&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;0.6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2015&lt;/TD&gt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t;&lt;TD&gt;2017&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2018&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2019&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&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;This is essentially the format of my dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For variable 1, I want the 2015 value replaced with an average of the 2014 and 2016 values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For variable 2, I want 2014 and 2015 values replaced with 2016 value and 2018 and 2019 values replaced with 2017 value&amp;nbsp;&lt;/P&gt;&lt;P&gt;For variable 3, I want 2015 replaced with 2014, 2016 replaced with 2017, and 2018 replaced with an average of 2017 and 2019&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2023 17:07:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885106#M349712</guid>
      <dc:creator>EpiMoby</dc:creator>
      <dc:date>2023-07-17T17:07:50Z</dc:date>
    </item>
    <item>
      <title>Re: Array for replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885113#M349713</link>
      <description>Do you have SAS/ETS?</description>
      <pubDate>Mon, 17 Jul 2023 17:19:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885113#M349713</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-07-17T17:19:38Z</dc:date>
    </item>
    <item>
      <title>Re: Array for replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885121#M349714</link>
      <description>&lt;P&gt;No only SAS 9.4&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2023 17:28:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885121#M349714</guid>
      <dc:creator>EpiMoby</dc:creator>
      <dc:date>2023-07-17T17:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: Array for replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885123#M349715</link>
      <description>You can check with  proc product_status;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 17 Jul 2023 17:30:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885123#M349715</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-07-17T17:30:31Z</dc:date>
    </item>
    <item>
      <title>Re: Array for replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885127#M349717</link>
      <description>&lt;P&gt;Here was the ouput:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3403 proc product_status;run;&lt;/P&gt;&lt;P&gt;For Base SAS Software ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;Image version information: 9.04.01M3P062415&lt;BR /&gt;For SAS/STAT ...&lt;BR /&gt;Custom version information: 14.1&lt;BR /&gt;For SAS/GRAPH ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;For SAS/ETS ...&lt;BR /&gt;Custom version information: 14.1&lt;BR /&gt;For SAS/FSP ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;For SAS/OR ...&lt;BR /&gt;Custom version information: 14.1&lt;BR /&gt;For SAS/AF ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;For SAS/IML ...&lt;BR /&gt;Custom version information: 14.1&lt;BR /&gt;For SAS/QC ...&lt;BR /&gt;Custom version information: 14.1&lt;BR /&gt;For SAS/ASSIST ...&lt;BR /&gt;Custom version information: 9.4&lt;BR /&gt;Image version information: 9.04.01M0P061913&lt;BR /&gt;For SAS/CONNECT ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;For SAS/TOOLKIT ...&lt;BR /&gt;Custom version information: 9.4&lt;BR /&gt;For SAS/GIS ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;For SAS/ACCESS to Hadoop ...&lt;BR /&gt;Custom version information: 9.43&lt;BR /&gt;For SAS/ACCESS to Postgres ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;For SAS Integration Technologies ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;For High Performance Suite ...&lt;BR /&gt;Custom version information: 2.2_M4&lt;BR /&gt;For SAS/ACCESS Interface to Oracle ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;For SAS/ACCESS Interface to PC Files ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;For SAS/ACCESS Interface to ODBC ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;For SAS/ACCESS Interface to OLE DB ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;For SAS/ACCESS Interface to MySQL ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;NOTE: PROCEDURE PRODUCT_STATUS used (Total process time):&lt;BR /&gt;real time 0.11 seconds&lt;BR /&gt;cpu time 0.07 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2023 17:34:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885127#M349717</guid>
      <dc:creator>EpiMoby</dc:creator>
      <dc:date>2023-07-17T17:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Array for replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885128#M349718</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/441521"&gt;@EpiMoby&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Here was the ouput:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3403 proc product_status;run;&lt;/P&gt;
&lt;P&gt;For Base SAS Software ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;Image version information: 9.04.01M3P062415&lt;BR /&gt;For SAS/STAT ...&lt;BR /&gt;Custom version information: 14.1&lt;BR /&gt;For SAS/GRAPH ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;&lt;FONT color="#339966"&gt;&lt;STRONG&gt;For SAS/ETS ...&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;&lt;STRONG&gt;Custom version information: 14.1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;For SAS/FSP ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;For SAS/OR ...&lt;BR /&gt;Custom version information: 14.1&lt;BR /&gt;For SAS/AF ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;For SAS/IML ...&lt;BR /&gt;Custom version information: 14.1&lt;BR /&gt;For SAS/QC ...&lt;BR /&gt;Custom version information: 14.1&lt;BR /&gt;For SAS/ASSIST ...&lt;BR /&gt;Custom version information: 9.4&lt;BR /&gt;Image version information: 9.04.01M0P061913&lt;BR /&gt;For SAS/CONNECT ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;For SAS/TOOLKIT ...&lt;BR /&gt;Custom version information: 9.4&lt;BR /&gt;For SAS/GIS ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;For SAS/ACCESS to Hadoop ...&lt;BR /&gt;Custom version information: 9.43&lt;BR /&gt;For SAS/ACCESS to Postgres ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;For SAS Integration Technologies ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;For High Performance Suite ...&lt;BR /&gt;Custom version information: 2.2_M4&lt;BR /&gt;For SAS/ACCESS Interface to Oracle ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;For SAS/ACCESS Interface to PC Files ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;For SAS/ACCESS Interface to ODBC ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;For SAS/ACCESS Interface to OLE DB ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;For SAS/ACCESS Interface to MySQL ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;NOTE: PROCEDURE PRODUCT_STATUS used (Total process time):&lt;BR /&gt;real time 0.11 seconds&lt;BR /&gt;cpu time 0.07 seconds&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You do have SAS ETS licensed. If you have flex in your methodology I'd suggest trying the methods in my initial response. If you're 100% set on methodology, you'll likely need a data step.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2023 17:37:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885128#M349718</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-07-17T17:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: Array for replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885132#M349719</link>
      <description>&lt;P&gt;Okay - I am very open to this and would like to learn.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would you be able to suggest draft code for this?&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2023 17:41:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885132#M349719</guid>
      <dc:creator>EpiMoby</dc:creator>
      <dc:date>2023-07-17T17:41:38Z</dc:date>
    </item>
    <item>
      <title>Re: Array for replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885136#M349721</link>
      <description>There is example code in the link, it really is that simple with ETS.&lt;BR /&gt;&lt;BR /&gt;Slightly different example. &lt;BR /&gt;&lt;A href="https://gist.github.com/statgeek/07a3708dee1225ceb9d4aa75daab2c52" target="_blank"&gt;https://gist.github.com/statgeek/07a3708dee1225ceb9d4aa75daab2c52&lt;/A&gt;</description>
      <pubDate>Mon, 17 Jul 2023 17:50:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885136#M349721</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-07-17T17:50:14Z</dc:date>
    </item>
    <item>
      <title>Re: Array for replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885162#M349731</link>
      <description>&lt;P&gt;Thank you - unfortunately the code isn't that simple to me. Ideally I would like to impute the data based on the following rules:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) if the variable is missing data for a year, such as 2015, then use the average of 2015 and 2016 for the imputed data&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) if the variable is missing data for a year without data available for the year prior and after, then use the closest year available regardless of whether that is above or below the missing year&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have any experience writing something like this for proc expand?&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2023 20:28:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885162#M349731</guid>
      <dc:creator>EpiMoby</dc:creator>
      <dc:date>2023-07-17T20:28:31Z</dc:date>
    </item>
    <item>
      <title>Re: Array for replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885182#M349746</link>
      <description>&lt;P&gt;As I mentioned above, if you're fixed on the methodology, then I don't believe ETS will work for you, you will need to write your own rules in a data step.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your methodology is flexible then ETS is an option.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input Year   State   Variable1  Variable2  Variable3;
date=mdy(1, 1, year);
format date year4.;
cards;
2014   1   0.2 .   0.6
2015   1   .   .   .
2016   1   0.5 0.6 .
2017   1   0.5 0.6 0.3
2018   1   0.6 .   .
2019   1   0.3 .   0.7
2014   2    .  .    2
2015   2            
2016   2            
2017   2            
2018   2            
2019   2            
2014   3            
2015   3            
2016   3            
2017   3            
2018   3            
2019   3 
;
run;

proc expand data=have out=want from=year extrapolate;
by state;
id date;
convert variable1=var1 variable2=var2 variable3=var3/ method = join ;
run;


title 'Interpolated';
proc print data=want;
run;
           &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Jul 2023 22:54:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885182#M349746</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-07-17T22:54:41Z</dc:date>
    </item>
    <item>
      <title>Re: Array for replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885197#M349757</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If a var is missing for a given year (say var{2016} is missing), then the mean(var{2015},var{2017}) would generate either&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The actual mean if both var{2015} and var{2017} are valid values&lt;BR /&gt;or&lt;/LI&gt;
&lt;LI&gt;The closest value if only one of var{2015} or var{2017} is a valid value.&lt;BR /&gt;or&lt;/LI&gt;
&lt;LI&gt;Otherwise miss.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;If you have case 3 (otherwise missing), then take the mean of var{2014} and var{2018}, i.e. expand the range by one year in each direction.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using that principle, then this code could work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let min_year=2014;
%let max_year=2019;
%let span=%eval(&amp;amp;max_year-&amp;amp;min_year);
%let array_lower_bound=%eval(&amp;amp;min_year-&amp;amp;span);
%let array_upper_bound=%eval(&amp;amp;max_year+&amp;amp;span);
%put _user_;

data have;
infile cards truncover;
input Year   State   a b c;
date=mdy(1, 1, year);
format date year4.;
cards;
2014   1   0.2 .   0.6
2015   1   .   .   .
2016   1   0.5 0.6 .
2017   1   0.5 0.6 0.3
2018   1   0.6 .   .
2019   1   0.3 .   0.7
2014   2    .  .    2
2015   2            
2016   2            
2017   2   . 0.4 .
2018   2   . 0.5 .  
2019   2            
2014   3            
2015   3            
2016   3            
2017   3            
2018   3            
2019   3  0.9 0.8 0.7
run;

data want (drop=v span);
  set have (in=firstpass)   have (in=secondpass) ;
  by state;

  array suspect_var {*}  a b c ;
  array ah{&amp;amp;array_lower_bound:&amp;amp;array_upper_bound,3} _temporary_;  /* Actual history */

  if first.state then call missing(of ah{*});

  if firstpass then do v=1 to dim(suspect_var);  /* Build the actual history array*/
    ah{year,v}=suspect_var{v};
  end;

  if secondpass;

  do v=1 to dim(suspect_var);
    do span=0 to &amp;amp;span while (suspect_var{v}=.);
      if n(ah{year-span,v},ah{year+span,v})&amp;gt;0 then suspect_var{v}=mean(ah{year-span,v},ah{year+span,v});
    end;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notice the array lower and upper bounds go beyond the actual earliest and latest years.&amp;nbsp; All those pre-study and post-study years will simply have missing values for each variable.&amp;nbsp; This allows a simplistic expansion of the span used to generate means without looking beyond the array bounds.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2023 04:05:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-for-replacing-missing-data/m-p/885197#M349757</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-07-18T04:05:00Z</dc:date>
    </item>
  </channel>
</rss>

