<?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: array q in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/array-q/m-p/412120#M100784</link>
    <description>&lt;P&gt;Do you get the same invalid data notes that I do when I run your code? 31SEP15 is not a valid date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any reason the dates weren't created as date values with the appropriate informat when created? I find that having actual date values usually simplifies code a lot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might show what your are expecting to get for a result.&lt;/P&gt;
&lt;P&gt;I think that you may have the direction of your comparisons backwards in the ELSE if, your loop is going to attempt to execute one too many times for most cases. If you want to stop as soon as you find the boundary value/variable the below shows an example.&lt;/P&gt;
&lt;PRE&gt;data a;
input subject $ visit $ labdt $ cd1 $ cd2 $ cd3 $ cd4 $;
cards;
101 1 15JUN15 17JUN15 18JUN15 29JUN15 31AUG15
101 2 20JUN15 17JUN15 18JUN15 29JUN15 31AUG15
101 3 01AUG15 17JUN15 18JUN15 29JUN15 31AUG15
102 1 19JUN15 17JUN15 28JUN15 29JUN15 30SEP15
102 1 28JUN15 17JUN15 28JUN15 29JUN15 30SEP15
;
run;

data b;
   set a;
   by subject visit;
   array vis[*] cd1-cd4;
   do i = 1 to (dim(vis) -1);

      if input(labdt,date7.) le input(vis[i],date7.) then do; 
         chk=vlabel(vis[i]);
         leave;
      end;
      else if input(labdt,date7.) ge input(vis[i],date7.) and input(labdt,date7.) le input((vis[i+1]),date7.)
      then do;
         chk=vlabel(vis[i+1]);
         leave;
      end;
   end;

run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;This assumes that the cd1 to cd4 are sorted in ascending order. &amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Nov 2017 20:38:45 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-11-09T20:38:45Z</dc:date>
    <item>
      <title>array q</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-q/m-p/412109#M100776</link>
      <description>&lt;P&gt;data a;&lt;BR /&gt;input subject $ visit $ labdt $ cd1 $ cd2 $ cd3 $ cd4 $;&lt;BR /&gt;cards;&lt;BR /&gt;101 1 15JUN15 17JUN15 18JUN15 29JUN15 31AUG15&lt;BR /&gt;101 2 20JUN15 17JUN15 18JUN15 29JUN15 31AUG15&lt;BR /&gt;101 3 01AUG15 17JUN15 18JUN15 29JUN15 31AUG15&lt;BR /&gt;102 1 19JUN15 17JUN15 28JUN15 29JUN15 31SEP15&lt;BR /&gt;102 1 28JUN15 17JUN15 28JUN15 29JUN15 31SEP15&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data b;&lt;BR /&gt;set a;&lt;BR /&gt;by subject visit;&lt;BR /&gt;array vis[*] cd1-cd4;&lt;BR /&gt;do i = 1 to dim(vis);&lt;BR /&gt;&lt;BR /&gt;if input(labdt,date9.) le input(vis[i],date9.) then chk=vlabel(vis[i]);&lt;BR /&gt;else if input(labdt,date9.) &amp;lt; input(vis[i],date9.) and input(labdt,date9.) ge input((vis[i+1]),date9.)&lt;BR /&gt;then chk=vlabel(vis[i+1]);&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;why isnt chk assgined properly. basically i want to check if labdt falls between which cdx variables?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thk&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2017 20:18:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-q/m-p/412109#M100776</guid>
      <dc:creator>eric2</dc:creator>
      <dc:date>2017-11-09T20:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: array q</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-q/m-p/412116#M100780</link>
      <description>&lt;P&gt;You should consider a binary search method instead of looping through the entire array as well...though it's likely the easiest approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't have a LEAVE, which you should, once your condition is met, otherwise, it will check each i regardless.&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>Thu, 09 Nov 2017 20:26:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-q/m-p/412116#M100780</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-09T20:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: array q</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-q/m-p/412120#M100784</link>
      <description>&lt;P&gt;Do you get the same invalid data notes that I do when I run your code? 31SEP15 is not a valid date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any reason the dates weren't created as date values with the appropriate informat when created? I find that having actual date values usually simplifies code a lot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might show what your are expecting to get for a result.&lt;/P&gt;
&lt;P&gt;I think that you may have the direction of your comparisons backwards in the ELSE if, your loop is going to attempt to execute one too many times for most cases. If you want to stop as soon as you find the boundary value/variable the below shows an example.&lt;/P&gt;
&lt;PRE&gt;data a;
input subject $ visit $ labdt $ cd1 $ cd2 $ cd3 $ cd4 $;
cards;
101 1 15JUN15 17JUN15 18JUN15 29JUN15 31AUG15
101 2 20JUN15 17JUN15 18JUN15 29JUN15 31AUG15
101 3 01AUG15 17JUN15 18JUN15 29JUN15 31AUG15
102 1 19JUN15 17JUN15 28JUN15 29JUN15 30SEP15
102 1 28JUN15 17JUN15 28JUN15 29JUN15 30SEP15
;
run;

data b;
   set a;
   by subject visit;
   array vis[*] cd1-cd4;
   do i = 1 to (dim(vis) -1);

      if input(labdt,date7.) le input(vis[i],date7.) then do; 
         chk=vlabel(vis[i]);
         leave;
      end;
      else if input(labdt,date7.) ge input(vis[i],date7.) and input(labdt,date7.) le input((vis[i+1]),date7.)
      then do;
         chk=vlabel(vis[i+1]);
         leave;
      end;
   end;

run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;This assumes that the cd1 to cd4 are sorted in ascending order. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2017 20:38:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-q/m-p/412120#M100784</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-11-09T20:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: array q</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-q/m-p/412123#M100787</link>
      <description>&lt;P&gt;thx LEAVE worked ..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thx again&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2017 20:39:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-q/m-p/412123#M100787</guid>
      <dc:creator>eric2</dc:creator>
      <dc:date>2017-11-09T20:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: array q</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-q/m-p/412126#M100789</link>
      <description>&lt;P&gt;If that's all you did, you will get error messages on some days, and not on other days.&amp;nbsp; It depends on what is in the data.&amp;nbsp; If you get as far as I=4, then what do you think will happen when your code references vis[I+1] ??&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2017 20:44:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-q/m-p/412126#M100789</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-11-09T20:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: array q</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-q/m-p/412132#M100793</link>
      <description>&lt;P&gt;i could have used full dates instead of date7.&amp;nbsp; &amp;nbsp;i believe the date will fall under one category only so do you think backward will produce different result than the current one?&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2017 20:58:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-q/m-p/412132#M100793</guid>
      <dc:creator>eric2</dc:creator>
      <dc:date>2017-11-09T20:58:05Z</dc:date>
    </item>
    <item>
      <title>Re: array q</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-q/m-p/412141#M100798</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/152094"&gt;@eric2&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;i could have used full dates instead of date7.&amp;nbsp; &amp;nbsp;i believe the date will fall under one category only so do you think backward will produce different result than the current one?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If I understand your question, likely the choice of date7 vs date9 shouldn't matter. I just try&amp;nbsp; to match the informat to actual range of characters/digits I have as there are some times that a longer informat than the value may cause problems.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the original dates had been read using date7 informat then the comparison code would be much cleaner and easier to follow.&lt;/P&gt;
&lt;P&gt;Plus if you need to do anything else, such as the difference between the test date and the boundary date you would have to convert the values again to use intck function.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2017 21:22:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-q/m-p/412141#M100798</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-11-09T21:22:42Z</dc:date>
    </item>
    <item>
      <title>Re: array q</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-q/m-p/412211#M100813</link>
      <description>&lt;P&gt;If CD1 &amp;lt;= CD2 &amp;lt;= CD3 &amp;lt;= CD4 then you&amp;nbsp;must stop&amp;nbsp;the loop as soon as labdt &amp;lt;= CDi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
set a;
array vis[*] cd1-cd4;
do i = 1 to dim(vis);

    if input(labdt,date9.) le input(vis[i],date9.) then do;
        chk=vlabel(vis[i]);
        leave;
        end;
    end;

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>Fri, 10 Nov 2017 04:39:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-q/m-p/412211#M100813</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-11-10T04:39:07Z</dc:date>
    </item>
  </channel>
</rss>

