@shawn123 wrote:
Thank you so much, so If Marco's statement and data step statement are writing together I need to treat them as separate statements?
It would help if I explained briefly how macro statements work.
When you write code with macro statements, and then run the code, the macro statement is resolved and replaced by non-macro code, which SAS then executes. So the part of your code (with one semicolon)
%if &i lt 5 %then assignment="&i";
is replaced by assignment="1" when &i=1 and this is not a complete SAS data step command, you have to have a semicolon at the end to complete the command.
A slightly superior way to write this is:
%if &i lt 5 %then assignment="&i"%str(;);
where the
%str(;)
resolves to a semicolon and this is the semicolon that ends the assignment="1" statement; and will only appear when &i lt 5.
So when &i is less than 5, the macro statement resolves to assignment="1"; (with a semicolon on the end)
When &i is greater than or equal to 5, the macro statement does not create any SAS code. (If you did it the original way you wrote the program, when &i is greater than or equal to 5, a semicolon is produced ... essentially a blank statement ending with a semicolon, and while in this simple example it makes no difference, there are other cases where it might make a difference)
--
Paige Miller