Calculating required sample size for an hypothesis test regarding a proportion Suppose we have the null and alternative hypotheses regarding a proportion
$H_0: p = p_0$
$H_a: p \ne p_0$
If we assume that $p$ takes the value $p_1$, what sample size do we need for a z-test of the null hypothesis at the $\alpha$ level with power $1 - \beta$?

One approximation to the power function is to use the p-value function.  The p-value for a score test of $H_0: p\le p_0$ vs $H_a: p > p_0$ is
$$H(p_0;\hat{p})=1-\Phi\bigg(\frac{\hat{p}-p_0}{\sqrt{p_0(1-p_0)/n}}\bigg).$$
At the minimum detectable effect $\hat{p}_{MDE}$ the p-value testing $H_0:p\le p_0$ equals the alpha level of the test, $H(p_0;\hat{p}_{MDE})=\alpha$.  For a given $n$ this p-value function evaluated at any other value $p$ is approximately equal to the power of the test,
$$1-\beta(p)\approx H(p;\hat{p}_{MDE})=1-\Phi\bigg(\frac{\hat{p}_{MDE}-p}{\sqrt{p(1-p)/n}}\bigg),$$
where the minimum detectable effect is $\hat{p}_{MDE}=p_0+z_{1-\alpha}\sqrt{p_0(1-p_0)/n}$.
This can be numerically solved for the sample size $n$.  This approach can be simplified even further by inverting a Wald test,
$$1-\beta(p)\approx H(p;\hat{p}_{MDE})=1-\Phi\bigg(\frac{\hat{p}_{MDE}-p}{\sqrt{\hat{p}_{MDE}(1-\hat{p}_{MDE})/n}}\bigg),$$
where the minimum detectable effect is $\hat{p}_{MDE}=p_0+z_{1-\alpha}\sqrt{\hat{p}_{MDE}(1-\hat{p}_{MDE})/n}$.  This is particularly useful in more complicated model.  Of course for a binomial proportion the power of a test can be solved exactly by identifying the rejection region of the test and then evaluating the complementary CDF of the binomial distribution under the alternative.
Here is a paper discussing inference on power as well as approximating power using a p-value function.
