<?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 Illegal Reference to the Array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Illegal-Reference-to-the-Array/m-p/664457#M198503</link>
    <description>&lt;P&gt;I have the following goal: To be able to flag any dates in my data file that would have year 2018.&lt;/P&gt;&lt;P&gt;I have 150 date variables so using an array seemed to be the most logical. I do not understand why I am getting the error:&amp;nbsp;Illegal Reference to the Array visitd. How do I make this work? Is there another way to flag dates that are off, based only on year that I am not thinking about? TIA.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code:&lt;/P&gt;&lt;P&gt;Data want;&lt;BR /&gt;Set have;&lt;BR /&gt;array visitd(150) V1dte --V150dte; /*I actually have each one listed here&lt;/P&gt;&lt;P&gt;format V1dte--V150dte mmddyy10.;&lt;BR /&gt;do i=1 to 150;&lt;BR /&gt;end;&lt;BR /&gt;retain referencedate '01JAN2018'd;&lt;BR /&gt;format referencedate mmddyy10.;&lt;BR /&gt;if visitd {i} ge referencedate then do;&lt;BR /&gt;output;&lt;BR /&gt;referencedate = visitd;&lt;BR /&gt;end;&lt;BR /&gt;Run;&lt;/P&gt;</description>
    <pubDate>Tue, 23 Jun 2020 19:44:11 GMT</pubDate>
    <dc:creator>Mscarboncopy</dc:creator>
    <dc:date>2020-06-23T19:44:11Z</dc:date>
    <item>
      <title>Illegal Reference to the Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Illegal-Reference-to-the-Array/m-p/664457#M198503</link>
      <description>&lt;P&gt;I have the following goal: To be able to flag any dates in my data file that would have year 2018.&lt;/P&gt;&lt;P&gt;I have 150 date variables so using an array seemed to be the most logical. I do not understand why I am getting the error:&amp;nbsp;Illegal Reference to the Array visitd. How do I make this work? Is there another way to flag dates that are off, based only on year that I am not thinking about? TIA.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code:&lt;/P&gt;&lt;P&gt;Data want;&lt;BR /&gt;Set have;&lt;BR /&gt;array visitd(150) V1dte --V150dte; /*I actually have each one listed here&lt;/P&gt;&lt;P&gt;format V1dte--V150dte mmddyy10.;&lt;BR /&gt;do i=1 to 150;&lt;BR /&gt;end;&lt;BR /&gt;retain referencedate '01JAN2018'd;&lt;BR /&gt;format referencedate mmddyy10.;&lt;BR /&gt;if visitd {i} ge referencedate then do;&lt;BR /&gt;output;&lt;BR /&gt;referencedate = visitd;&lt;BR /&gt;end;&lt;BR /&gt;Run;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jun 2020 19:44:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Illegal-Reference-to-the-Array/m-p/664457#M198503</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2020-06-23T19:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: Illegal Reference to the Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Illegal-Reference-to-the-Array/m-p/664462#M198506</link>
      <description>You have an end right after your DO loop for some reason and another at the end where it likely should be. Delete the first one. Because you i = 151 at the end of the loop, you're then trying to use your array with 151 which isn't a valid index.</description>
      <pubDate>Tue, 23 Jun 2020 19:50:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Illegal-Reference-to-the-Array/m-p/664462#M198506</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-23T19:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: Illegal Reference to the Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Illegal-Reference-to-the-Array/m-p/664494#M198523</link>
      <description>&lt;P&gt;Let's begin with what you are trying to achieve.&amp;nbsp; Then we can talk about how to get the result you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What does it mean to flag each date that is off?&amp;nbsp; Do you want 150 flags, one for each date?&amp;nbsp; Do you want to output each "off" date as a separate observation?&amp;nbsp; What additional variables would need to be in the data set to identify where the "off" date came from?&amp;nbsp; Your program, even with errors corrected, doesn't make your intention clear.&amp;nbsp; So specify what the result should be first.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jun 2020 21:53:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Illegal-Reference-to-the-Array/m-p/664494#M198523</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-06-23T21:53:49Z</dc:date>
    </item>
    <item>
      <title>Re: Illegal Reference to the Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Illegal-Reference-to-the-Array/m-p/664500#M198527</link>
      <description>&lt;P&gt;Hi. Any date with year 2018 is a mistake in coding. I am trying to generate a file with all of the 2018 dates so I can delete them from my data file. Most dates are before 2018 so it won't be 150 flags. The file has about 150 entries for different ids - some ids have 10 dates, some have 100, some have 150 (and several other variables). Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jun 2020 22:13:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Illegal-Reference-to-the-Array/m-p/664500#M198527</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2020-06-23T22:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: Illegal Reference to the Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Illegal-Reference-to-the-Array/m-p/664506#M198531</link>
      <description>&lt;P&gt;Thank you. I tried that but it did not work.&lt;/P&gt;&lt;P&gt;format mba160V1dte--mba160V150dte mmddyy10.;&lt;BR /&gt;do i=1 to 150;&lt;BR /&gt;retain referencedate '01JAN2018'd;&lt;BR /&gt;format referencedate mmddyy10.;&lt;BR /&gt;if visitd{i} ge referencedate then do;&lt;BR /&gt;output;&lt;BR /&gt;referencedate = visitd;&lt;BR /&gt;end;&lt;BR /&gt;end;&amp;nbsp; /* the end I removed from above as suggested, must be here as Sas tells me I have one unclosed do block&lt;BR /&gt;Run;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jun 2020 22:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Illegal-Reference-to-the-Array/m-p/664506#M198531</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2020-06-23T22:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: Illegal Reference to the Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Illegal-Reference-to-the-Array/m-p/664507#M198532</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data want;
Set have;
array visitd(150) V1dte --V150dte; 
format V1dte--V150dte mmddyy10.;

flag=0;
do i=1 to 150 while(flag = 0);
    if year(visitd {i}) = 2018 then flag=1;
end;

Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Any record with a flag=1 has a date with 2018 in it.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jun 2020 22:25:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Illegal-Reference-to-the-Array/m-p/664507#M198532</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-23T22:25:09Z</dc:date>
    </item>
    <item>
      <title>Re: Illegal Reference to the Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Illegal-Reference-to-the-Array/m-p/664509#M198534</link>
      <description>&lt;P&gt;Perfect! Thank you so much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jun 2020 22:34:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Illegal-Reference-to-the-Array/m-p/664509#M198534</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2020-06-23T22:34:19Z</dc:date>
    </item>
    <item>
      <title>Re: Illegal Reference to the Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Illegal-Reference-to-the-Array/m-p/664570#M198573</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/210474"&gt;@Mscarboncopy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi. Any date with year 2018 is a mistake in coding. I am trying to generate a file with all of the 2018 dates so I can delete them from my data file. Most dates are before 2018 so it won't be 150 flags. The file has about 150 entries for different ids - some ids have 10 dates, some have 100, some have 150 (and several other variables). Thanks.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You suffer from a bad data structure. In a case where you have only 10 dates, the space for the other 140 columns is wasted needlessly.&lt;/P&gt;
&lt;P&gt;The bigger problem you have is that you need to do complicated coding for a VERY SIMPLE issue.&lt;/P&gt;
&lt;P&gt;With a long dataset layout, it is just&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if Vdte ge '01jan2018'd;
keep ID Vdte; /*add any other variable needed, like SEQ derived from your original column name */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So you should, as a first step in making your life easier, transpose your 150 columns to a long dataset layout, and drop any observations that have missing values.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 07:21:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Illegal-Reference-to-the-Array/m-p/664570#M198573</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-24T07:21:38Z</dc:date>
    </item>
  </channel>
</rss>

