<?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: Return column with most recent date, array error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Return-column-with-most-recent-date-array-error/m-p/634066#M188165</link>
    <description>&lt;P&gt;I initially did this so I could use _NUMERIC_ to define the array, without using the ID variable. I still need the ID variable - is there a better way to achieve this? The data set I'm using has many variables for the array, and are likely to change. Should I force the ID as a character instead?&lt;/P&gt;</description>
    <pubDate>Mon, 23 Mar 2020 11:10:58 GMT</pubDate>
    <dc:creator>MB_Analyst</dc:creator>
    <dc:date>2020-03-23T11:10:58Z</dc:date>
    <item>
      <title>Return column with most recent date, array error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Return-column-with-most-recent-date-array-error/m-p/634064#M188163</link>
      <description>&lt;P&gt;I was using the answer to &lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-Get-Maximum-Row-s-Value-with-its-Name-of-Variable-into/td-p/326629" target="_self"&gt;this question&lt;/A&gt;, in order to return the column name with the latest date. My data is in this format:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
    INPUT id away :DATE9. home :DATE9. travel :DATE9.;
    FORMAT away home travel DATE9.;
DATALINES;
1 . . 01JAN2020
2 03JAN2020 . 03FEB2020
3 04FEB2020 01JAN2020 12FEB2020
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Using the solution to the other question I have this code (I didn't want to include the ID in the array, so I had to drop it, then bring it back in):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA want;
    SET have(drop=id);
    ARRAY dates[*] _numeric_;
    SET have;
    latest = max(of dates[*]);
    maxv = vname(dates[whichn(latest, of dates(*))]);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Everything runs fun if I leave out the line maxv = vname..., but leaving it in gives me an error:&lt;/P&gt;
&lt;P&gt;ERROR: Array subscript out of range at line 1068 column 18.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is causing this error to come up in the last line of the code?&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 11:01:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Return-column-with-most-recent-date-array-error/m-p/634064#M188163</guid>
      <dc:creator>MB_Analyst</dc:creator>
      <dc:date>2020-03-23T11:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: Return column with most recent date, array error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Return-column-with-most-recent-date-array-error/m-p/634065#M188164</link>
      <description>You have TWO "SET have;" , drop the last one .</description>
      <pubDate>Mon, 23 Mar 2020 11:08:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Return-column-with-most-recent-date-array-error/m-p/634065#M188164</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-03-23T11:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: Return column with most recent date, array error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Return-column-with-most-recent-date-array-error/m-p/634066#M188165</link>
      <description>&lt;P&gt;I initially did this so I could use _NUMERIC_ to define the array, without using the ID variable. I still need the ID variable - is there a better way to achieve this? The data set I'm using has many variables for the array, and are likely to change. Should I force the ID as a character instead?&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 11:10:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Return-column-with-most-recent-date-array-error/m-p/634066#M188165</guid>
      <dc:creator>MB_Analyst</dc:creator>
      <dc:date>2020-03-23T11:10:58Z</dc:date>
    </item>
    <item>
      <title>Re: Return column with most recent date, array error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Return-column-with-most-recent-date-array-error/m-p/634067#M188166</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/182623"&gt;@MB_Analyst&lt;/a&gt;&amp;nbsp; Your code successfully ran when i tested. Here is the log&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
1716  DATA have;
1717      INPUT id away :DATE9. home :DATE9. travel :DATE9.;
1718      FORMAT away home travel DATE9.;
1719  DATALINES;

NOTE: The data set WORK.HAVE has 3 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


1723  ;
1724
1725  DATA want;
1726      SET have(drop=id);
1727      ARRAY dates[*] _numeric_;
1728      SET have;
1729      latest = max(of dates[*]);
1730      maxv = vname(dates[whichn(latest, of dates(*))]);
1731  RUN;

NOTE: There were 3 observations read from the data set WORK.HAVE.
NOTE: There were 3 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 3 observations and 6 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Btw, this makes me wonder whether your sample data is a good representative of your real?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also does any of your records have all missings that eventually makes the MAX value also as missing? Please verify&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 11:30:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Return-column-with-most-recent-date-array-error/m-p/634067#M188166</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-23T11:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: Return column with most recent date, array error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Return-column-with-most-recent-date-array-error/m-p/634068#M188167</link>
      <description>It was a missing value in the MAX. I was able to avoid the error with:&lt;BR /&gt;If NOT MISSING(latest) THEN DO;&lt;BR /&gt;    maxv = vname(dates[whichn(latest, of dates(*))]);&lt;BR /&gt;END;</description>
      <pubDate>Mon, 23 Mar 2020 11:37:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Return-column-with-most-recent-date-array-error/m-p/634068#M188167</guid>
      <dc:creator>MB_Analyst</dc:creator>
      <dc:date>2020-03-23T11:37:52Z</dc:date>
    </item>
    <item>
      <title>Re: Return column with most recent date, array error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Return-column-with-most-recent-date-array-error/m-p/634070#M188168</link>
      <description>&lt;P&gt;Good and I am glad. You are not alone. I have had that issue many times. The thumb rule is always to be very cognizant of &lt;STRONG&gt;missing&lt;/STRONG&gt; values and its propagation.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 11:51:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Return-column-with-most-recent-date-array-error/m-p/634070#M188168</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-23T11:51:24Z</dc:date>
    </item>
  </channel>
</rss>

