If you have enough memory, you may be able to do this with a hash object.
Be warned: this code is untested, as I don't have a SAS installation to hand. However the basic idea should work. You iterate through the data step, adding each node to the hash object, and on the last object you set macro variables to the size of the hash object.
data _null_;
set links end=lastrec;
format node_id 8.;
if _N_ eq 1 then do;
declare hash h();
h.defineKey("node_id");
h.defineDone();
end;
node_id = from_id;
rc=h.find();
if rc ne 0 then h.add();
node_id = to_id;
rc=h.find();
if rc ne 0 then h.add();
if lastrec then do;
call symput('numLinks', put(h.num_items, 8. -L));
call symput('numEdges', put(_N_, 8. -L));
end;
run;