<?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 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/array/m-p/478909#M123544</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a dataset and i need to compare 4 records against lab date and output the earliest rslt where cdx is less than lbdt. Any suggestions?&lt;/P&gt;&lt;P&gt;data a;&lt;BR /&gt;input subject $ labdt $ cd1 $ cd2 $ cd3 $ cd4 $ rslt;&lt;BR /&gt;cards;&lt;BR /&gt;101 15JUN15 17JUN15 18JUN15 29JUN15 31AUG15 22&lt;BR /&gt;101 20JUN15 17JUN15 18JUN15 29JUN15 31AUG15 23&lt;BR /&gt;101 01AUG15 17JUN15 18JUN15 29JUN15 31AUG15 45&lt;BR /&gt;102 19JUN15 17JUN15 28JUN15 29JUN15 30SEP15 44&lt;BR /&gt;102 28JUN15 17JUN15 28JUN15 29JUN15 30SEP15 47&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;I need the result as&lt;/P&gt;&lt;P&gt;subject date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rslt&lt;/P&gt;&lt;P&gt;&amp;nbsp;101&amp;nbsp; &amp;nbsp; &amp;nbsp;17JUN2015&amp;nbsp; 22&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;101&amp;nbsp; &amp;nbsp; &amp;nbsp;18JUN2015&amp;nbsp; 22&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;101&amp;nbsp; &amp;nbsp; &amp;nbsp;29JUN2015&amp;nbsp; 23&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;101&amp;nbsp; &amp;nbsp; &amp;nbsp;31AUG2015&amp;nbsp; 23&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;records 3 and 4 are 23 as the earliest rslt less than cd3, cd4 date compared to labdate is 23.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thx&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Jul 2018 04:51:10 GMT</pubDate>
    <dc:creator>eric2</dc:creator>
    <dc:date>2018-07-18T04:51:10Z</dc:date>
    <item>
      <title>array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array/m-p/478909#M123544</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a dataset and i need to compare 4 records against lab date and output the earliest rslt where cdx is less than lbdt. Any suggestions?&lt;/P&gt;&lt;P&gt;data a;&lt;BR /&gt;input subject $ labdt $ cd1 $ cd2 $ cd3 $ cd4 $ rslt;&lt;BR /&gt;cards;&lt;BR /&gt;101 15JUN15 17JUN15 18JUN15 29JUN15 31AUG15 22&lt;BR /&gt;101 20JUN15 17JUN15 18JUN15 29JUN15 31AUG15 23&lt;BR /&gt;101 01AUG15 17JUN15 18JUN15 29JUN15 31AUG15 45&lt;BR /&gt;102 19JUN15 17JUN15 28JUN15 29JUN15 30SEP15 44&lt;BR /&gt;102 28JUN15 17JUN15 28JUN15 29JUN15 30SEP15 47&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;I need the result as&lt;/P&gt;&lt;P&gt;subject date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rslt&lt;/P&gt;&lt;P&gt;&amp;nbsp;101&amp;nbsp; &amp;nbsp; &amp;nbsp;17JUN2015&amp;nbsp; 22&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;101&amp;nbsp; &amp;nbsp; &amp;nbsp;18JUN2015&amp;nbsp; 22&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;101&amp;nbsp; &amp;nbsp; &amp;nbsp;29JUN2015&amp;nbsp; 23&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;101&amp;nbsp; &amp;nbsp; &amp;nbsp;31AUG2015&amp;nbsp; 23&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;records 3 and 4 are 23 as the earliest rslt less than cd3, cd4 date compared to labdate is 23.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thx&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 04:51:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array/m-p/478909#M123544</guid>
      <dc:creator>eric2</dc:creator>
      <dc:date>2018-07-18T04:51:10Z</dc:date>
    </item>
    <item>
      <title>Re: array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array/m-p/478914#M123546</link>
      <description>&lt;P&gt;or i can have the two datasets as below&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;data a;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;input subject $ labdt $ rslt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;cards;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;101 15JUN15&amp;nbsp; 22&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;101 20JUN15&amp;nbsp; 23&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;101 01AUG15&amp;nbsp; 45&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;102 19JUN15&amp;nbsp; 44&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;102 28JUN15&amp;nbsp; 47&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;data b;&lt;BR /&gt;input subject $ cd $ ;&lt;BR /&gt;cards;&lt;BR /&gt;101&amp;nbsp; 17JUN15 &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;101 18JUN15 &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;101 29JUN15 &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;101 31AUG15&amp;nbsp;&lt;BR /&gt;102&amp;nbsp; 17JUN15 &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;102 28JUN15 &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;102 29JUN15 &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;102 30SEP15&amp;nbsp;&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 05:16:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array/m-p/478914#M123546</guid>
      <dc:creator>eric2</dc:creator>
      <dc:date>2018-07-18T05:16:01Z</dc:date>
    </item>
    <item>
      <title>Re: array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array/m-p/478917#M123548</link>
      <description>Maybe it's the lack of coffeine, but where is the variable lbdt? Please fix the description so that the variables you have in your example datasets are used.</description>
      <pubDate>Wed, 18 Jul 2018 05:21:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array/m-p/478917#M123548</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2018-07-18T05:21:34Z</dc:date>
    </item>
    <item>
      <title>Re: array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array/m-p/478918#M123549</link>
      <description>&lt;P&gt;there is no labdt in dataset b as i need to compare dates in dataset b against a and pull out the result where dates in a is less than b. so total obs in final dataset should be equal to dataset b&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 05:23:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array/m-p/478918#M123549</guid>
      <dc:creator>eric2</dc:creator>
      <dc:date>2018-07-18T05:23:54Z</dc:date>
    </item>
    <item>
      <title>Re: array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array/m-p/478925#M123552</link>
      <description>&lt;P&gt;correct result in last record should be 45 and not 23 as 01aug is less than 31aug for sub 101&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 05:43:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array/m-p/478925#M123552</guid>
      <dc:creator>eric2</dc:creator>
      <dc:date>2018-07-18T05:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array/m-p/478928#M123554</link>
      <description>Your description is confusing. You saisd "I have a dataset and i need to compare 4 records against lab date and output the earliest rslt where cdx is less than lbdt." - still not clear where to find the variable lbdt.</description>
      <pubDate>Wed, 18 Jul 2018 05:55:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array/m-p/478928#M123554</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2018-07-18T05:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array/m-p/478979#M123582</link>
      <description>&lt;P&gt;its&amp;nbsp; labdt and not lbdt which is present in dataset a&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 10:39:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array/m-p/478979#M123582</guid>
      <dc:creator>eric2</dc:creator>
      <dc:date>2018-07-18T10:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array/m-p/479132#M123625</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;I have a dataset and i need to compare 4 records against lab date and &lt;STRONG&gt;output the earliest rslt where cdx is less than lbdt.&lt;/STRONG&gt; Any suggestions?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input subject $ labdt $ cd1 $ cd2 $ cd3 $ cd4 $ rslt;
cards;
101 15JUN15 17JUN15 18JUN15 29JUN15 31AUG15 22
101 20JUN15 17JUN15 18JUN15 29JUN15 31AUG15 23
&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;101 01AUG15 17JUN15 18JUN15 29JUN15 31AUG15 45&lt;/STRONG&gt;&lt;/FONT&gt;
102 19JUN15 17JUN15 28JUN15 29JUN15 30SEP15 44
102 28JUN15 17JUN15 28JUN15 29JUN15 30SEP15 47
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For the Third Record your text says the result is 23, but you show 45.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The 17th JUN is the earliest date and it's less than the lab date of 01August so I'm confused as to how the result is not 45 in your output. Or do you want the latest result that's before lab date which corresponds to the most recent before the lab, which is the max, not the min.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And how does the RSLT not just stay the same, how does the CD align with the results?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming you actually want the largest value before the lab date the logic would be as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    informat labdt cd1 cd2 cd3 cd4 date9.;
    format labdt cd: date9.;
    input subject $ labdt cd1 cd2 cd3 cd4 rslt;
    cards;
101 15JUN15 17JUN15 18JUN15 29JUN15 31AUG15 22
101 20JUN15 17JUN15 18JUN15 29JUN15 31AUG15 23
101 01AUG15 17JUN15 18JUN15 29JUN15 31AUG15 45
102 19JUN15 17JUN15 28JUN15 29JUN15 30SEP15 44
102 28JUN15 17JUN15 28JUN15 29JUN15 30SEP15 47
;

data want;
    set have;
    array cd(4) cd1-cd4;
    call sortn(of cd(*)); *sort the array in ascending order;

    do i=dim(cd) to 1 by -1; *loop through it backwards, starting from max;

        if cd(i) &amp;lt;=labdt then
            do;
                * check if less than lab date;
                max=cd(i);
                leave;
            end;
    end;
    format max date9.;
    keep subject labdt max rslt;
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;</description>
      <pubDate>Wed, 18 Jul 2018 16:40:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array/m-p/479132#M123625</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-18T16:40:08Z</dc:date>
    </item>
    <item>
      <title>Re: array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array/m-p/479552#M123819</link>
      <description>&lt;P&gt;Thanks Reeza.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jul 2018 15:57:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array/m-p/479552#M123819</guid>
      <dc:creator>eric2</dc:creator>
      <dc:date>2018-07-19T15:57:23Z</dc:date>
    </item>
  </channel>
</rss>

