Keith's roughly correct in that the correct approach is what he shows, but the reasoning isn't accurate. LAG works on data; input and output is irrelevant (and not really a meaningful distinction). It is, in fact, quite possible to make this work with only programmatically provided data.
data lagtest;
do a=1 to 3;
b=lag(a);
output;
end;
run;
Similarly, it's possible to make the second example not work, with a somewhat absurd example:
data lagtest2;
p=1;
set lagtest2 point=p;
b= lag(a);
output;
p=2;
set lagtest2 point=p;
b=lag(a);
output;
p=3;
set lagtest2 point=p;
b=lag(a);
output;
stop;
run;
The reason the first example doesn't work isn't the source of data; it's the number of lag calls. One of the most common mistakes is to believe that lag retrieves a value from previous record; that isn't true. The way lag works is that each call to lag creates a queue. Each time that lag statement is encountered, whatever value is in the argument is pushed onto the queue, and if the queue is at least the defined length+1 long, the value at the front of the queue is popped off. (For lag or lag1, the queue must be 2 long; for lag2 it must be 3 long; etc. - ie, the number of the function plus the value just popped on).
In your first example, you call lag three times, so three separate queues are created, and none of them ever are called a second time. In your second example, you call lag once, so one queue is created, and it is called three times.