<?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 until loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/do-until-loop/m-p/593221#M170214</link>
    <description>&lt;P&gt;And here is a reason that &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;requested that you use the {I} or "running man" opened code box:&lt;/P&gt;
&lt;PRE&gt;113 if dv&amp;gt;lag(dv) then do until dv
__
22
76
ERROR 22-322: Syntax error, expecting one of the following: (, =.
ERROR 76-322: Syntax error, statement will be ignored.
&lt;/PRE&gt;
&lt;P&gt;Besides all of the extra blank lines, if you had copied directly from your log and pasted into a code box the _ (underscore character) above would have been under the place in the line where SAS determined a problem existed. Likely something more like:&lt;/P&gt;
&lt;PRE&gt;113 if dv&amp;gt;lag(dv) then do until dv 
                                _ 
                               22 
                               76 
ERROR 22-322: Syntax error, expecting one of the following: (, =. 
ERROR 76-322: Syntax error, statement will be ignored. &lt;/PRE&gt;
&lt;P&gt;which shows that a "(" was expected before the variable DV in the UNTIL,&amp;nbsp; as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;solution indicated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The main message windows on this forum will reformat text when pasted, removing white space such as leading blanks. The code box will maintain plain text formatting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 01 Oct 2019 22:32:55 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-10-01T22:32:55Z</dc:date>
    <item>
      <title>do until loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-until-loop/m-p/592865#M170049</link>
      <description>&lt;P&gt;I have the data set test where I need to have the 24 hour time point for dv to be less than the 20 hour time point for dv based upon the calculation dv=ipred(1+eps1) +eps2 which is possible since the eps1 and eps2 are based upon a random function..&amp;nbsp; In those cases such as for subjects 2,3,and 4 I would like to have the dv at time 24 to be less than the dv&amp;nbsp;time at 20 hrs.&amp;nbsp; Thus I want it to recalculate until dv&amp;lt;lag(dv)&amp;nbsp; then exit.&amp;nbsp; However I can't determine if the logic of my code works &amp;nbsp;since I can't figure out how to code for less than in the do until loop and I get a syntax&amp;nbsp;error&amp;nbsp; stating "expecting one of the following (, =.)."&lt;/P&gt;&lt;P&gt;I need to know how to correct my&amp;nbsp;code or is there another way to accomplish this task perhaps with proc seql?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input Subject Time dv ipred eps1 eps2;
datalines;
1 10 10 8  0.01 0.1
1  12 5 3  0.01 0.1
1 20 10 8  0.01 0.1
1 24 5  3  0.01 0.1
2 10 40 38 0.01 0.1
2  12 20 18 0.01 0.1
2 20 10 8  0.01 0.1
2 24 15 14 0.01 0.1
3 10 5 3  0.01 0.1
3  12 21   0.01 0.1
3 20 20 19 0.01 0.1
3 24 30 32 0.01 0.1
4 10 5 3   0.01 0.1
4  12 21 1 0.01 0.1
4 20 20 15 0.01 0.1
4 24 30 25 0.01 0.1

;
run;



data old;
set test;
retain subject dv lagdv dv  eps1 eps2;
if time in (20 24);
lagdv=lag(dv);
%let eps1=0.0025;
%let eps2=0.096;
eps1=rand('LOGNORMAL')*sqrt(&amp;amp;eps1);
eps2=ranD('LOGNORMAL')*sqrt(&amp;amp;eps2);
dv=ipred*(1+eps1) + eps2;
array subs subject;
do i=1 to dim(subs);
if dv&amp;gt;lag(dv) then do until dv&amp;lt;lag(dv);
output;
keep subject time lagdv dv  eps1 eps2;
end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2019 23:49:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-until-loop/m-p/592865#M170049</guid>
      <dc:creator>jacksonan123</dc:creator>
      <dc:date>2019-09-30T23:49:37Z</dc:date>
    </item>
    <item>
      <title>Re: do until loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-until-loop/m-p/592866#M170050</link>
      <description>&lt;P&gt;So, first you have an error in the log. Show us the entire log for this step, the code AND the error message, by clicking on the {i} icon and paste the entire log for this step (not just the error message) into the window that appears.&amp;nbsp;&lt;STRONG&gt;Do not show us the log any other way&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you take one example, and work through the results by hand, and then show us the desired output? Even better yet, in this example, show us the hand-calculations so we can see exactly what you want to do. It is unnerving to hear someone say they can't even determine if they are getting the right results, how would we know what the right results are to help you, if you don't tell us the right results?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lastly, you have made this code unnecessarily complicated so its impossible to determine what you really are trying to do. You might try starting over and trying to simplify as much as possible ... by removing the macro variables which are completely unnecessary, removing the ARRAY of length 1, which is also completely unnecessary, and I also suspect you don't need the RETAIN statement.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 00:06:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-until-loop/m-p/592866#M170050</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-10-01T00:06:02Z</dc:date>
    </item>
    <item>
      <title>Re: do until loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-until-loop/m-p/592913#M170072</link>
      <description>The result that I would like to have and I will use only subject #4 as an&lt;BR /&gt;example but it would be done for all subjects.&lt;BR /&gt;&lt;BR /&gt;Original data&lt;BR /&gt;&lt;BR /&gt;Subject Time DV IPRED eps1 eps2&lt;BR /&gt;&lt;BR /&gt;4 10 5 3 0.01 0.1&lt;BR /&gt;&lt;BR /&gt;4 12 21 1 0.01 0.1&lt;BR /&gt;&lt;BR /&gt;4 20 20 15 0.01 0.1&lt;BR /&gt;&lt;BR /&gt;4 24 30 25 0.01 0.1&lt;BR /&gt;&lt;BR /&gt;Recalculation of values at 20 and 24 hrs which will result in a number at 24&lt;BR /&gt;hrs less than the value at 20 hrs&lt;BR /&gt;&lt;BR /&gt;4 10 5 3 0.01&lt;BR /&gt;0.1&lt;BR /&gt;&lt;BR /&gt;4 12 21 1 0.01&lt;BR /&gt;0.1&lt;BR /&gt;&lt;BR /&gt;4 20 (new value) 15 0.01 0.1&lt;BR /&gt;&lt;BR /&gt;4 24 (value lt 20) 25 0.01 0.1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The log is:&lt;BR /&gt;&lt;BR /&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;BR /&gt;&lt;BR /&gt;72&lt;BR /&gt;&lt;BR /&gt;73&lt;BR /&gt;&lt;BR /&gt;74&lt;BR /&gt;&lt;BR /&gt;75&lt;BR /&gt;&lt;BR /&gt;76 data test;&lt;BR /&gt;&lt;BR /&gt;77 input Subject Time dv ipred eps1 eps2;&lt;BR /&gt;&lt;BR /&gt;78 datalines;&lt;BR /&gt;&lt;BR /&gt;NOTE: SAS went to a new line when INPUT statement reached past the end of a&lt;BR /&gt;line.&lt;BR /&gt;&lt;BR /&gt;NOTE: The data set WORK.TEST has 15 observations and 6 variables.&lt;BR /&gt;&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;&lt;BR /&gt;real time 0.01 seconds&lt;BR /&gt;&lt;BR /&gt;cpu time 0.02 seconds&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;96 ;&lt;BR /&gt;&lt;BR /&gt;97 run;&lt;BR /&gt;&lt;BR /&gt;98&lt;BR /&gt;&lt;BR /&gt;99&lt;BR /&gt;&lt;BR /&gt;100&lt;BR /&gt;&lt;BR /&gt;101 data old;&lt;BR /&gt;&lt;BR /&gt;102 set test;&lt;BR /&gt;&lt;BR /&gt;103 retain subject dv lagdv dv eps1 eps2;&lt;BR /&gt;&lt;BR /&gt;104 if time in (20 24);&lt;BR /&gt;&lt;BR /&gt;105 lagdv=lag(dv);&lt;BR /&gt;&lt;BR /&gt;106 %let eps1=0.0025;&lt;BR /&gt;&lt;BR /&gt;107 %let eps2=0.096;&lt;BR /&gt;&lt;BR /&gt;108 eps1=rand('LOGNORMAL')*sqrt(&amp;amp;eps1);&lt;BR /&gt;&lt;BR /&gt;109 eps2=ranD('LOGNORMAL')*sqrt(&amp;amp;eps2);&lt;BR /&gt;&lt;BR /&gt;110 dv=ipred*(1+eps1) + eps2;&lt;BR /&gt;&lt;BR /&gt;111 array subs subject;&lt;BR /&gt;&lt;BR /&gt;112 do i=1 to dim(subs);&lt;BR /&gt;&lt;BR /&gt;113 if dv&amp;gt;lag(dv) then do until dv&lt;BR /&gt;__&lt;BR /&gt;&lt;BR /&gt;22&lt;BR /&gt;&lt;BR /&gt;76&lt;BR /&gt;&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: (, =.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;BR /&gt;&lt;BR /&gt;114 output;&lt;BR /&gt;&lt;BR /&gt;115 keep subject time lagdv dv eps1 eps2;&lt;BR /&gt;&lt;BR /&gt;116 end;&lt;BR /&gt;&lt;BR /&gt;117 end;&lt;BR /&gt;&lt;BR /&gt;118 run;&lt;BR /&gt;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;&lt;BR /&gt;WARNING: The data set WORK.OLD may be incomplete. When this step was&lt;BR /&gt;stopped there were 0 observations and 6 variables.&lt;BR /&gt;&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;&lt;BR /&gt;cpu time 0.00 seconds&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;119&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 01 Oct 2019 04:16:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-until-loop/m-p/592913#M170072</guid>
      <dc:creator>jacksonan123</dc:creator>
      <dc:date>2019-10-01T04:16:32Z</dc:date>
    </item>
    <item>
      <title>Re: do until loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-until-loop/m-p/593114#M170158</link>
      <description>The UNTIL clause (and the WHILE clause) in a DO statement must have its argument in parentheses.  So "do until dv;", if logically appropriate, should be "do until (dv);".</description>
      <pubDate>Tue, 01 Oct 2019 16:46:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-until-loop/m-p/593114#M170158</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-10-01T16:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: do until loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-until-loop/m-p/593221#M170214</link>
      <description>&lt;P&gt;And here is a reason that &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;requested that you use the {I} or "running man" opened code box:&lt;/P&gt;
&lt;PRE&gt;113 if dv&amp;gt;lag(dv) then do until dv
__
22
76
ERROR 22-322: Syntax error, expecting one of the following: (, =.
ERROR 76-322: Syntax error, statement will be ignored.
&lt;/PRE&gt;
&lt;P&gt;Besides all of the extra blank lines, if you had copied directly from your log and pasted into a code box the _ (underscore character) above would have been under the place in the line where SAS determined a problem existed. Likely something more like:&lt;/P&gt;
&lt;PRE&gt;113 if dv&amp;gt;lag(dv) then do until dv 
                                _ 
                               22 
                               76 
ERROR 22-322: Syntax error, expecting one of the following: (, =. 
ERROR 76-322: Syntax error, statement will be ignored. &lt;/PRE&gt;
&lt;P&gt;which shows that a "(" was expected before the variable DV in the UNTIL,&amp;nbsp; as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;solution indicated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The main message windows on this forum will reformat text when pasted, removing white space such as leading blanks. The code box will maintain plain text formatting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 22:32:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-until-loop/m-p/593221#M170214</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-01T22:32:55Z</dc:date>
    </item>
    <item>
      <title>Re: do until loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-until-loop/m-p/593223#M170215</link>
      <description>Yes, that was the issue and thanks for your feedback.&lt;BR /&gt;</description>
      <pubDate>Tue, 01 Oct 2019 22:52:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-until-loop/m-p/593223#M170215</guid>
      <dc:creator>jacksonan123</dc:creator>
      <dc:date>2019-10-01T22:52:32Z</dc:date>
    </item>
  </channel>
</rss>

