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.. 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 time at 20 hrs. Thus I want it to recalculate until dv<lag(dv) then exit. However I can't determine if the logic of my code works since I can't figure out how to code for less than in the do until loop and I get a syntax error stating "expecting one of the following (, =.)."
I need to know how to correct my code or is there another way to accomplish this task perhaps with proc seql?
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(&eps1);
eps2=ranD('LOGNORMAL')*sqrt(&eps2);
dv=ipred*(1+eps1) + eps2;
array subs subject;
do i=1 to dim(subs);
if dv>lag(dv) then do until dv<lag(dv);
output;
keep subject time lagdv dv eps1 eps2;
end;
end;
run;
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. Do not show us the log any other way.
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?
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.
And here is a reason that @PaigeMiller requested that you use the {I} or "running man" opened code box:
113 if dv>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.
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:
113 if dv>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.
which shows that a "(" was expected before the variable DV in the UNTIL, as @mkeintz solution indicated.
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.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.