10-26-2017 01:27 PM
The following code works as expected.
data have; set have; by veh_no; if veh_no="&num" then do; if var1 ne '0' then do; if first.var1 then cusumvar1=0; cusumvar1+1; end; end; run;
However, when I add a similar if then loop I get an error message.
ERROR 22-322: Syntax error, expecting one of the following: (, +, =.
data have; set have; by veh_no; if veh_no="&num" then do; if var1 ne '0' then do; if first.var1 then cusumvar1=0; cusumvar1+1; end; if var2 ne '0' then do; if first.var2 then cusumvar2=0; cusumvar2+1; end; end; run;
10-26-2017 01:57 PM
A few notes might help push you in the right direction ...
First, don't use DATA HAVE; SET HAVE; when you are experimenting and trying to get a program to work. If an experiment fails (but doesn't generate an error message), you will have replaced your data with a poor substitute.
Second, either you didn't show the code you ran, or your expectations are bizarre. There is no way the top program ran "as expected" when you include this combination of statements:
IF FIRST.VAR1 THEN ...
The program doesn't create FIRST.VAR1. At a minimum, the log should give you a message to that effect.
Finally, is this code part of a macro? If not, you should be able to pinpoint in the log which statement the error message refers to.
10-26-2017 02:00 PM
When debugging programs with macro-variables always turn on options mprint and symbolgen. Posting the log will make debugging easier, because without your data we are unable to reproduce the problem you have.
There is an error in your first data-step, you can't use
without having var1 in the BY-statement.
The if-then-statement is not a loop