Construi algo parecido asi... pero si tienes la posibilidad de colocar un var_dump o un var_export de la data que usas para generar la primera tabla seria mucho mas sencillo la forma de como construir/reconstruir la matriz para sacar los datos...
$perYear = array(
2001 => array('venezuela' => 1, 'peru' => 2) ,
2002 => array('venezuela' => 1, 'peru' => 2) ,
2003 => array('venezuela' => 1, 'peru' => 2)
);
$dataPerYear = array();
foreach ($perYear as $theYear => $theDataOfTheYear){
foreach ($theDataOfTheYear as $thisCountry => $theDataOfTheCountry){
$dataPerYear[$theYear][$thisCountry] = $theDataOfTheCountry;
print 'Del Año: '.$theYear.' el pais: '.$thisCountry.' Vendio'.$theDataOfTheCountry."\n";
}
}