The data step always loops until something stops it. So I would restate the question as:
How does SAS know when to STOP looping through the data?
What normally stops a data step is when it reads past the end of its inputs.
In your example when the INPUT statement finds there are no more lines to read from Pumpkin.dat.
In the case of a data step that reads in SAS datasets (with SET or MERGE statement for example) it normally stops when the SET or MERGE finds no more observations to read.
Other ways to stop a data step are :
the STOP statement.
a step that has no inputs knows it does not need to loop.
A step that does have inputs but because of conditional logic fails to read from any of them in a pass through the implied loop will write a note and stop.
... View more