Americans bought fewer pharmaceuticals, cellphones and cars from other countries, and cut purchases of foreign machinery and other supplies.