Welcome to TRS
1990 to 2000 Rangers used the 4.0l OHV engine
2001 and up Rangers got the 4.0l SOHC engines
These are different engines, no relation to each other
You could do this swap since you have complete 1999 donor vehicle
Besides the engine and transmission you would need to swap over the 1999 computer and engine wiring harness.
2002 computer can't run the 4.0l OHV engine very well, and engine wiring wouldn't match up since they are different engines.
When you swap computers you also need to swap Keys, because of PATS anti-theft, so swap ignition cylinders and door locks(if you want same key to work for both)
There would also be some other changes needed with 1999 computer in a 2002, i.e. speedometer and 4x4 control
The 4.0l SOHC rated 205 horsepower
4.0l OHV 160 horsepower
So not really a great swap for the cost and labor involved
Selling the running 4.0l OHV and transmission to someone with a 1995-2000 Ranger then using that money to fix or replace the 4.0l SOHC and trans in the 2002, IMO, would be a better direction, you get a newer stock vehicle without all the wiring hassles
Or even a 5.0l V8 swap into the 2002, same labor as 4.0l OHV swap but better results
Depending on where you live there may be other implications when you change the type of engine in a vehicle, because the VIN number will no longer match the vehicle, 8th digit in the Ford VIN tells what engine was installed at the factory
4.0l SOHC and 4.0l OHV used different VIN, as would a V8
So you may end up with a Salvage Title or Rebuilt Title, using stock engine you won't
If there is emissions testing required then in most cases you can't use an engine older than the year of the vehicle, so you can't put a '99 engine, of any size, into an '02 vehicle