Loop is initialized correct, however you're missing several "END"s - one for the "IF OPEN(input.." line and one for the "DO UNTIL EOF(inp.." line - that's why the program thinks it has finished already.
Just add them at the right place which would be: --- cut here --- CLOSE(input1) CLOSE(output)
END /* That's the END for the "DO UNTIL EOF..." line END /* That's the END for the "IF OPEN(inp.." line
END
EXIT --- cut here ---
Using indention in the source would make such pitfalls more visible.