<?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 over the same observation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213104#M39367</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Recommend you pair down your DATA step logic, perhaps using a stable instream DATALINES; data sample - not your input.&amp;nbsp; And make use of DATA step PUTLOG _ALL_; to observe SAS behavior when in very controlled process.&amp;nbsp; This will provide you some insight as to a possible technique / variation, and then implement the simple technique to adapt to your desired input / output data scenario.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It will be to your benefit to leverage the SAS processing behavior experience with various DIAGNOSTIC techniques, such as OPTIONS MGEN SGEN MLOGIC;&amp;nbsp;&amp;nbsp; and PUTLOG as suggested with your own SAS code-piece -- as much (or more for experience gaining) as it would be to pose questions / wait / reply / then iterate....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 12 May 2015 19:41:05 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2015-05-12T19:41:05Z</dc:date>
    <item>
      <title>Do Loop over the same observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213092#M39355</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Hello!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;I'm trying to make this bit of code more robust:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE style="border: 0px; font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;TBODY style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;if 99 le days le 182 then&amp;nbsp; visit='6 month';&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;else if days le ceil(((9*30.5)+14)) then visit='9 month';&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;else if days le ceil(((12*30.5)+14)) then visit='12 month';&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;else if days le ceil(((15*30.5)+14)) then visit='15 month';&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;else if days le ceil(((18*30.5)+14)) then visit='18 month';&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;else if days le ceil(((21*30.5)+14)) then visit='21 month';&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;else if days le ceil(((24*30.5)+14)) then visit='24 month';&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;else if days le ceil(((27*30.5)+14)) then visit='27 month';&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;else if days le ceil(((30*30.5)+14)) then visit='30 month';&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;else if days le ceil(((33*30.5)+14)) then visit='33 month';&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;else if days le ceil(((36*30.5)+14)) then visit='36 month';&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;else if days le ceil(((39*30.5)+14)) then visit='39 month';&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;else if days le ceil(((42*30.5)+14)) then visit='42 month';&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;&lt;/TD&gt;&lt;TD style="padding-right: 4px; padding-left: 4px; border: 0px; font-style: inherit; font-family: inherit;"&gt;else if days le ceil(((45*30.5)+14)) then visit='45 month';&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;And have been able to somewhat make it more robust using this method:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;do i=9 by 3 until(last.id);&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; set origvisits;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; days = VISITDTC -trtstdt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; label days='Number of days since original ib1001 start';&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; if 99 le days le 182 then&amp;nbsp; visit='6 month';&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; by id ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; %let n=i;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; if days le ceil(((i*30.5)+14)) then visit=strip(&amp;amp;n||' month');&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; else if days le ceil((((3+i)*30.5)+14)) then visit=strip(&amp;amp;n+3||' month');&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; else if days le ceil((((6+i)*30.5)+14)) then visit=strip(&amp;amp;n+6||' month');&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; else if days le ceil((((9+i)*30.5)+14)) then visit=strip(&amp;amp;n+9||' month');&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; else if days le ceil((((12+i)*30.5)+14)) then visit=strip(&amp;amp;n+12||' month');&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; output;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;But its still is not robust enough.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.3333330154419px; font-family: inherit;"&gt;What I've constructed above is each observation is being read in with i=9 and increasing by 3 until last.id. And then i increments sequentially for each observation within that by group (id, in this case)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.3333330154419px; font-family: inherit;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.3333330154419px; font-family: inherit;"&gt;What I really want SAS to do is read one observation at a time and keep trying values of i (the index of the do loop) until the condition &lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.3333330154419px; font-family: inherit;"&gt;if days le ceil(((i*30.5)+14))&amp;nbsp; is true, so that I can assign a nominal visit date.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.3333330154419px; font-family: inherit;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.3333330154419px; font-family: inherit;"&gt;For example, suppose the condition&amp;nbsp; days le (9*30.5)+14 is not true, I want SAS to stay with that same observation and try (12*30.5)+14, if that condition is not true then try (15*30.5)+14 until the &lt;STRONG style="font-style: inherit; font-size: 13.3333320617676px; font-family: inherit;"&gt;days le (i*30.5)+14&lt;/STRONG&gt; condition is true. Then move on to the next observation in the dataset, with i being reset back to 9.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.3333330154419px; font-family: inherit;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.3333330154419px; font-family: inherit;"&gt;I hope this makes sense, I know what I want SAS to do...but can't quite articulate it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.3333330154419px; font-family: inherit;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.3333330154419px; font-family: inherit;"&gt;Any help or guidance would be appreciated&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 May 2015 17:13:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213092#M39355</guid>
      <dc:creator>sahotah</dc:creator>
      <dc:date>2015-05-11T17:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop over the same observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213093#M39356</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The way to make this more robust is to consider the two dates involved in the calculation of &lt;STRONG&gt;days&lt;/STRONG&gt; and to use SAS date handling functions &lt;STRONG&gt;INTNX&lt;/STRONG&gt; and &lt;STRONG&gt;INTCK&lt;/STRONG&gt; in the determination of the &lt;STRONG&gt;visit&lt;/STRONG&gt; value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 May 2015 17:41:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213093#M39356</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-05-11T17:41:11Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop over the same observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213094#M39357</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The second date in the comparison is being derived so that I can assign a nominal visit. The number of days between visit date and treatment start date (days = VISITDTC -trtstdt) is a fixed value for each observation. Now what I need to do is derive a nominal visit for that value of days, based on what is specified in our protocol (months*30.5)+14.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lets assume days= 452. So I start the loop with i=9. (9*30.5)+14=289. Since 452 is not less than 289, a nominal visit wont be assigned, the loop moves on to the next observation. Instead, what I want to happen is now with that same observation have it evaluate the condition for i=12 ---&amp;gt; (12*30.5)+14=380. 452 is still not less than 380, so lets move on to i=15. (15*30.5)+14 =472. Bingo! 452 is less than 472. This visit is assigned a nominal visit of 15 months.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Move on to the next observation, and start the same process with i=9 until the condition days le (i*30.5)+14 is met.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that clarifies what I am looking to accomplish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 May 2015 18:09:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213094#M39357</guid>
      <dc:creator>sahotah</dc:creator>
      <dc:date>2015-05-11T18:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop over the same observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213095#M39358</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are mixing SAS DATA step processing MACRO language (%LET stmt) which is resolved typically at DATA / PROC step compilation.&amp;nbsp; Suggest looking at using PROC FORMAT to assign/derive VISIT based on pre-defined&amp;nbsp; value ranges.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, consider opportunity to start out your post by explaining what it is you intend/desire to accomplish in most basic terms -- as well show an abbreviated data-sample (both INPUT side and OUTPUT).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Scott Barry&lt;BR /&gt;SBBWorks, Inc.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 May 2015 18:12:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213095#M39358</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2015-05-11T18:12:02Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop over the same observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213096#M39359</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the suggestion. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The PROC FORMAT won't be useful in this case, since I would have to continually add date values, etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I want is to automate this process, by the example stated above. I just want to loop values of i for one observation at a time until a condition is satisfied,&amp;nbsp; then move on to the next observation and start the loop over (in this case, starting over means starting at i=9) and continue to loop through values of i until the condition &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;days le (i*30.5)+14 is met.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you know if there is a way to accomplish this? Basically telling SAS to read in an observation, hold it there, try different values of i (starting at 9, incrementing by 3) until &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;days le (i*30.5)+14 is true, then move on to the obs and start the process over.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 May 2015 18:20:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213096#M39359</guid>
      <dc:creator>sahotah</dc:creator>
      <dc:date>2015-05-11T18:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop over the same observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213097#M39360</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, it's not exactly clear what you mean by "robust" here.&amp;nbsp; Doesn't cover a wide enough date range?&amp;nbsp; Sometimes gives the wrong answer?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At any rate, you may not need a loop at all.&amp;nbsp; You could start here:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if days ge 183 then n_months = (days - 14) / 30.5;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tweak the formula if that would be appropriate, then apply functions such as CEIL, ROUND, etc. as needed to generate VISIT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I do agree with PGStats that it might be more accurate to go back to the variables used to compute DAYS as your starting point.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 May 2015 18:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213097#M39360</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-05-11T18:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop over the same observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213098#M39361</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, I guess what I mean by robust is a solution that is not so data-driven. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A clinical trial can go on for years and years (which can produce a lot of three month intervals). I want to be able to capture all three month intervals and assign a nominal visit. We have a "formula" for calculating a nominal visit spelled out in our protocol; in this case its (months*30.5)+14.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All I want to do is "plug-n-chug" different values of i (starting at 9, increment by 3) for each individual observation (row of data)&amp;nbsp; in my data set until the condition &lt;STRONG&gt;days le (i*30.5) +14 &lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;is satisfied. Then move on to the next observation. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In my partial solution, I came up with this:&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;do i=9 by 3 until(last.id);&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; set origvisits;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; days = VISITDTC -trtstdt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; label days='Number of days since original ib1001 start';&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; if 99 le days le 182 then&amp;nbsp; visit='6 month';&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; by id ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; %let n=i;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; if days le ceil(((i*30.5)+14)) then visit=strip(&amp;amp;n||' month');&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; else if days le ceil((((3+i)*30.5)+14)) then visit=strip(&amp;amp;n+3||' month');&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; else if days le ceil((((6+i)*30.5)+14)) then visit=strip(&amp;amp;n+6||' month');&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; else if days le ceil((((9+i)*30.5)+14)) then visit=strip(&amp;amp;n+9||' month');&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; else if days le ceil((((12+i)*30.5)+14)) then visit=strip(&amp;amp;n+12||' month');&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; output;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;end;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Which could potentially not cover all the values I need, that is I can "run out" of nominal visits. You see I'm kind of forcing SAS to go to the next i (by adding 3) if the condition is not met.&amp;nbsp; &lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Is there a way where I can tell SAS to do something of the effect&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;if days le ceil(((i*30.5)+14)) then visit=strip(&amp;amp;n||' month');&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if try the next value of i and perform the same calculation as above until you get an answer&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 May 2015 18:45:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213098#M39361</guid>
      <dc:creator>sahotah</dc:creator>
      <dc:date>2015-05-11T18:45:56Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop over the same observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213099#M39362</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay,so you need a RETAIN SAS variable to use as a base-increment for each observation you iterate.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Suggest some self-initiated desk-checking using PUTLOG "&amp;gt;LBL-nnn" / _ALL_;&amp;nbsp; so that you can decipher DATA step iterations along the path of your program -- the "nnn" you would identify so that you can identify "I am here".....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And so check your DO statement syntax, for example:&amp;nbsp;&amp;nbsp;&amp;nbsp; DO&amp;nbsp; I=9&amp;nbsp; TO&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp; BY -1&amp;nbsp; UNTIL(&amp;lt;condition);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Scott Barry&lt;/P&gt;&lt;P&gt;SBBWorks, Inc.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 May 2015 18:48:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213099#M39362</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2015-05-11T18:48:32Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop over the same observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213100#M39363</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your initial method is inefficient - it will work but not easily scalable or understandable as you're seeing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does the following get you close? You probably still need your first if condition to deal with the less than 9 months interval.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;months=(days-14)/30.5;&lt;/P&gt;&lt;P&gt;months3=floor(months/3)*3;&lt;/P&gt;&lt;P&gt;month_category = put(months3, 2.)||" month";&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 May 2015 19:00:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213100#M39363</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-05-11T19:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop over the same observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213101#M39364</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ha! Wow, so much simpler than I ever thought. Elegant and simple, exactly what I was looking for!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 May 2015 21:07:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213101#M39364</guid>
      <dc:creator>sahotah</dc:creator>
      <dc:date>2015-05-11T21:07:29Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop over the same observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213102#M39365</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As much as I love this solution, looks like I need to do something as I mentioned before so that it will comply with our protocol and statistical analysis plan. Is there a way to iterate values of i one observation at a time...like how I was attempting to explain earlier?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 May 2015 19:17:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213102#M39365</guid>
      <dc:creator>sahotah</dc:creator>
      <dc:date>2015-05-12T19:17:47Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop over the same observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213103#M39366</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;From your example and as was conveyed, you cannot mix macro language within DATA step iteration, so you will need to increment a second SAS DATA step variable (maybe call it n, used as in N+1;) and then make use of that variable when you assign VISIT although using a PUT(N,3.) combined with your other sub-character value assignments.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Scott Barry&lt;/P&gt;&lt;P&gt;SBBWorks, Inc.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 May 2015 19:37:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213103#M39366</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2015-05-12T19:37:18Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop over the same observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213104#M39367</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Recommend you pair down your DATA step logic, perhaps using a stable instream DATALINES; data sample - not your input.&amp;nbsp; And make use of DATA step PUTLOG _ALL_; to observe SAS behavior when in very controlled process.&amp;nbsp; This will provide you some insight as to a possible technique / variation, and then implement the simple technique to adapt to your desired input / output data scenario.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It will be to your benefit to leverage the SAS processing behavior experience with various DIAGNOSTIC techniques, such as OPTIONS MGEN SGEN MLOGIC;&amp;nbsp;&amp;nbsp; and PUTLOG as suggested with your own SAS code-piece -- as much (or more for experience gaining) as it would be to pose questions / wait / reply / then iterate....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 May 2015 19:41:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-over-the-same-observation/m-p/213104#M39367</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2015-05-12T19:41:05Z</dc:date>
    </item>
  </channel>
</rss>

