... siempre reemplazas el id anterior... solo pon órden:
Código PHP:
Id anterior: echo $_SESSION['idanterior'];
$id = $datos['id'];
$_SESSION['idanterior'] = $datos['id'];
... ten en cuenta que inicialmente la variable no existirá (ó no debería de existir).
Edito: ... el texto "Id anterior:", ¿no lo imprimes??
Código PHP:
echo "Id anterior: ".$_SESSION['idanterior'];
$id = $datos['id'];
$_SESSION['idanterior'] = $datos['id'];