For the easiest swap, use a 99-01 engine -- that will have the EGR valve. There are different electronics and parts for 99-01 models, and 02-04 models, so match them up if you can. Some 01.5 - 02 models had the 98-01 electronics, less the EGR valve, this may be the case with the engine you are looking at. EGR's were eliminated all together after 02... If need be, you can add the EGR valve and wiring harness from your old engine, provided it has the 98-01 electronics already.
If your new engine is an 02-04, with some extra work it can be converted to run in your 99, check out this thread for what needs to be swapped (says 3.2./3.5, but parts are same for 2.7):