If you want Sparabara to hold the line against a phalanx, then you're going to need superior numbers of Sparabara. They're no match for a phalanx unit for unit, but they'll hold long enough if you have enough of them in deep formations.

Either that or you'll have to seriously whittle down the phalanxes with missiles before they make contact, and flank them when they do. Fighting defensively helps a lot, you can site your army on the high ground, and give your slingers and archers enough range to shoot the phalanxes to hell as they march up, before they even lower their sarissas (long pikes). After that a unit of Sparabara should do OK against a half-strength phalanx.