<?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: Do loop error problem in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638394#M8989</link>
    <description>&lt;P&gt;Another issue with your code.&lt;/P&gt;
&lt;PRE&gt;do i=1 to 13;
fydate(i+1)=fydate(i)+365.25;
end;&lt;/PRE&gt;
&lt;P&gt;When i=13 then you reference a 14th item in the array: fydate(i+1) is fydate(14). You define the array explicitly with 13 elements so the attempt to use a 14th element will generate an out of bounds error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another concern when I see variables with DATE names and then fractional values is that perhaps you want to reconsider the initial values and what you mean by "+365.25".&lt;/P&gt;
&lt;P&gt;If you have an actual SAS date value the function INTNX will increment values by given intervals and account for things like leap days without having to deal with fractional days. If you have date value then&lt;/P&gt;
&lt;P&gt;newdatevar = intnx('year',datevar,1,'S') will return the same day of the next year for example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And proper date values allow use of SAS date formats to create analysis groups by changing formats without having to create additional variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt; has a PDF with much information about dates.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Apr 2020 17:00:04 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-04-08T17:00:04Z</dc:date>
    <item>
      <title>Do loop error problem</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638346#M8984</link>
      <description>&lt;P&gt;Hi guys, I am a SAS starter.I just want to build new variables with the do loop, here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data pnm_sur; set part3.pnm_sur;&lt;BR /&gt;fy1date=cv3date+365.25;&lt;BR /&gt;array fydate(13) fy1date--fy13date;&lt;BR /&gt;do i=1 to 13;&lt;BR /&gt;fydate(i+1)=fydate(i)+365.25;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Errors happens "&amp;nbsp;ERROR: fy13date does not follow fy1date on the list of previously defined variables.&lt;BR /&gt;ERROR: Too few variables defined for the dimension(s) specified for the array fydate."&lt;/P&gt;&lt;P&gt;I don't know how to figure it out and I want your help. Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 15:53:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638346#M8984</guid>
      <dc:creator>Yaqun</dc:creator>
      <dc:date>2020-04-08T15:53:57Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop error problem</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638348#M8985</link>
      <description>&lt;P&gt;Your variables&amp;nbsp;&lt;SPAN&gt;fy1date--fy13date are not consecutive, with fy13date coming somewhere after fy1date. Or maybe there aren't 13 variables in this variable list. You need to look at the data set&amp;nbsp;part3.pnm_sur with your own eyes and see what is in there in terms of these variables. You probably will have to specify the array differently, depending on what you see in&amp;nbsp;part3.pnm_sur.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 16:02:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638348#M8985</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-08T16:02:49Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop error problem</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638351#M8986</link>
      <description>&lt;P&gt;Hi PaigeMiller,&lt;/P&gt;&lt;P&gt;Thanks a lot for your quick reply!&lt;/P&gt;&lt;P&gt;I see my problem. I thought "array" may develop new variables, actually it cannot.&lt;/P&gt;&lt;P&gt;I develop fy1date to fy13date in the former step and it works!&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 16:19:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638351#M8986</guid>
      <dc:creator>Yaqun</dc:creator>
      <dc:date>2020-04-08T16:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop error problem</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638356#M8987</link>
      <description>&lt;P&gt;If you want to create the variables in the array in data set&amp;nbsp;&lt;SPAN&gt;pnm_sur, you need&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array fydate(13) fydate1-fydate13;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note the single dash and the fact that the number of the variable is at the end. This is a valid list of 13 variables named consecutively, and in the ARRAY statement creates these 13 variables if they don't already exist.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 16:38:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638356#M8987</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-08T16:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop error problem</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638373#M8988</link>
      <description>&lt;P&gt;New variables &lt;STRONG&gt;will&lt;/STRONG&gt; be created if they are first mentioned in an ARRAY statement.&lt;/P&gt;
&lt;P&gt;Your problem is that position based variable list can only work with variables that already exist.&amp;nbsp; By definition. &lt;STRONG&gt;A variable cannot have a position if it does not exist yet.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 16:52:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638373#M8988</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-08T16:52:17Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop error problem</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638394#M8989</link>
      <description>&lt;P&gt;Another issue with your code.&lt;/P&gt;
&lt;PRE&gt;do i=1 to 13;
fydate(i+1)=fydate(i)+365.25;
end;&lt;/PRE&gt;
&lt;P&gt;When i=13 then you reference a 14th item in the array: fydate(i+1) is fydate(14). You define the array explicitly with 13 elements so the attempt to use a 14th element will generate an out of bounds error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another concern when I see variables with DATE names and then fractional values is that perhaps you want to reconsider the initial values and what you mean by "+365.25".&lt;/P&gt;
&lt;P&gt;If you have an actual SAS date value the function INTNX will increment values by given intervals and account for things like leap days without having to deal with fractional days. If you have date value then&lt;/P&gt;
&lt;P&gt;newdatevar = intnx('year',datevar,1,'S') will return the same day of the next year for example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And proper date values allow use of SAS date formats to create analysis groups by changing formats without having to create additional variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt; has a PDF with much information about dates.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 17:00:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638394#M8989</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-08T17:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop error problem</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638422#M8990</link>
      <description>That is exactly what I want to do! Thanks a lot !</description>
      <pubDate>Wed, 08 Apr 2020 18:04:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638422#M8990</guid>
      <dc:creator>Yaqun</dc:creator>
      <dc:date>2020-04-08T18:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop error problem</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638431#M8991</link>
      <description>&lt;P&gt;I changed my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data pnm_sur;set part3.pnm_sur;&lt;BR /&gt;array fydate (14) fydate1-fydate14;&lt;BR /&gt;fydate1= intnx('year',cv3date,1,'S');&lt;BR /&gt;do i=1 to 13;&lt;BR /&gt;fydate(i+1)=intnx('year',fydate(i),1,'S');&lt;BR /&gt;end;&lt;BR /&gt;do i=1 to 14;&lt;BR /&gt;format fydate(i) MMDDYY10.;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But there still some errors with the format:&amp;nbsp;ERROR 85-322: Expecting a format name. It did not consider&amp;nbsp;fydate(i)&amp;nbsp; as a format name?&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 18:35:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638431#M8991</guid>
      <dc:creator>Yaqun</dc:creator>
      <dc:date>2020-04-08T18:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop error problem</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638434#M8992</link>
      <description>&lt;P&gt;This statement is not valid syntax:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format fydate(i) MMDDYY10.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The format statement needs actual variable names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format fydate1-fydate14 mmddyy10. ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You seem to have over complicated things.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i=1 to dim(fydate);
  fydate(i)=intnx('year',cv3date,i,'S');
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Apr 2020 18:41:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638434#M8992</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-08T18:41:36Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop error problem</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638435#M8993</link>
      <description>&lt;P&gt;It works when the code change to&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data pnm_sur;set part3.pnm_sur;&lt;BR /&gt;array fydate (14) fydate1-fydate14;&lt;BR /&gt;fydate1= intnx('year',cv3date,1,'S');&lt;BR /&gt;do i=1 to 13;&lt;BR /&gt;fydate(i+1)=intnx('year',fydate(i),1,'S');&lt;BR /&gt;end;&lt;BR /&gt;format fydate1--fydate14 MMDDYY10.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So do loop cannot be used in format? or the reason is something else&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 18:42:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638435#M8993</guid>
      <dc:creator>Yaqun</dc:creator>
      <dc:date>2020-04-08T18:42:06Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop error problem</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638436#M8994</link>
      <description>&lt;P&gt;Doesn't make any sense to put a FORMAT statement inside a DO loop.&amp;nbsp; It is not executed, it just sets the metadata of the variable(s) listed.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 18:43:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638436#M8994</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-08T18:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop error problem</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638437#M8995</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/320318"&gt;@Yaqun&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So do loop cannot be used in format? or the reason is something else&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Unfortunately, I don't understand this. What problem are you having? Please be specific.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 18:44:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638437#M8995</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-08T18:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop error problem</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638438#M8996</link>
      <description>I see what you mean. That is helpful!</description>
      <pubDate>Wed, 08 Apr 2020 18:46:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638438#M8996</guid>
      <dc:creator>Yaqun</dc:creator>
      <dc:date>2020-04-08T18:46:19Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop error problem</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638440#M8997</link>
      <description>I put a FORMAT statement inside a DO loop. It is not executed. I know it does not make any sense now. Thank you!</description>
      <pubDate>Wed, 08 Apr 2020 18:48:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Do-loop-error-problem/m-p/638440#M8997</guid>
      <dc:creator>Yaqun</dc:creator>
      <dc:date>2020-04-08T18:48:35Z</dc:date>
    </item>
  </channel>
</rss>

