Know your step boundaries!
Will the DATA Step below execute as is?
data a; infile 'c:\temp\myfile.txt'; input x y z; |
No. A RUN statement or other step boundary is required to mark the end of the DATA Step and cause the step to execute.
Will the DATA Step below execute as is?
data a; infile datalines; input x y z; datalines; 1 2 3 4 5 6 ; |
Yes. The DATALINES statement marks the end of DATA Step statements. The semi-colon after the data lines causes the DATA Step to execute.
Is it OK to put a RUN statement after the semi-colon following the data lines?
data a; infile datalines; input x y z; datalines; 1 2 3 4 5 6 ; run; |
Yes. The RUN statement is harmless but unnecessary. An extra step boundary is not required. The RUN statement has no effect.
4 Comments
To expand on Michelle Holmes comment, the first DATA step will also execute in a batch environment because the end of the program file also marks the end of the DATA step. It will also run in any environment if there is another step following it.
Is it OK not to use infile in the following data step?
data a;
infile datalines;
input x y z;
cards;
1 2 3
;
Yes. The INFILE statement here is harmless but unnecessary. :-)
You are right in saying that a "run" statement is not needed when "datalines" is used. Nevertheless, it is a good programming practice to use "run" for the sake of consistency and readability.
I think a caveat to your questions above is the SAS environment in which you run the program... The first program won't run in Foundation SAS as you point out but will in SAS Enterprise Guide due to the internal SAS statements SAS Enterprise Guide submits after every request sent.