Solving an ODE from a PDE 
Solve this differential equation:
  $$z^2\frac{dR}{R}+\frac{z\,dz}{1+z^2}=\frac{dS}{S}\tag1$$

I tried separating the variables but could not. Also tried to show that LHS is of the form of the differential of a product of functions but could not.
Originally this is coming from a PDE 
$$z\frac{\partial n}{\partial x}dx+\frac{n\,dz}{1+z^2}=\frac{1}{z}\cdot \frac{\partial n}{\partial y}dy\tag2$$
where $z=\frac{dy}{dx}$ and $n=n(x,y)$ and $y=y(x)$.
The first equation can be obtained from $(2)$ by substituting $n=R(x)S(y)$.
Please tell me how to solve the differential equations. Any suggestions for a general approach for solution of the PDE is also welcome.
ADDENDUM: The equation $(2)$ has been obtained from solving the Euler Lagrange equation  for a ray of light travelling through a medium with refractive index $n(x,y)$.
Now here, $L=L(y,y',x)=n(x,y(x))\sqrt{1+y'^2}$ where $y'=\frac{dy}{dx}$
So we solve $\frac{d}{dx}\left(\frac{\partial L}{\partial y'}\right)=\frac{\partial L}{\partial y}$ and accordingly get equation $(2)$.
 A: Your differential equation  (Euler-Lagrange) is 
$$\frac{d}{dx}\left(n(x,y)\, \frac{1}{\sqrt{1 + \left(\frac{dy}{dx}\right)^2}} \,  \, \frac{dy}{dx}\right) = \frac{\partial n}{\partial y}(x,y) \, \sqrt{1 + \left(\frac{dy}{dx}\right)^2}$$ where the unknown function is $y = y(x)$ and $x$ is the independent variable. The rest of the functions, such as $n(x,y)$ and $\frac{\partial n}{\partial y}(x,y)$ are known. Observe that if you perform fully the differentiation in the left-had side of the equation, this equation is of the form 
$$F\left(x, \, y , \, \frac{dy}{dx}, \, \frac{d^2 y}{dx^2}\right) = 0$$  If you let $$p = n(x,y)\, \frac{1}{\sqrt{1 + \left(\frac{dy}{dx}\right)^2}} \,  \, \frac{dy}{dx}$$ which is called Legendre's transformation $p = \frac{\partial \mathcal{L}}{\partial{y'}}$, you get the system 
\begin{align}
\frac{dy}{dx} =& \frac{p}{\sqrt{n(x,y)^2 - p^2}}\\
\frac{dp}{dx} =&  \frac{\partial n}{\partial y}(x,y) \, \frac{n(x, y)}{\sqrt{n(x,y)^2 - p^2}}
\end{align}
where the unknown functions are $y=y(x)$ and $p = p(x)$. This is a Hamiltonian system. Having a general function $n(x,y)$ implies that your chances of explicitly solving these equations are close to zero. It has to be some very special $n(x,y)$ for that to happen. However, if $n(x,y) = n(y)$ your chances increase because you have a conserved quantity, called energy or Hamiltonian function (a first integral). Even the case $n(x,y) = R(x)S(y)$ is not obviously solvable explicitly. If you want try changing the variables of the Euler-Lagrange equation by $X = R(x)$ and $Y = S(y)$ and switch the derivatives to $\frac{dY}{dX}$ and $\frac{d}{dx} = \frac{dR}{dx}\frac{d}{dX}$ although I don't see immediate benefit from that. 
Edit. There are several things one can do depending on what the situation is, meaning what $n(x,y)$ is. Assume $n(x,y) > 0$. Then if you reparametrize the solutions of your system using parameter $t\in \mathbb{R}$, you get $x=x(t)$ and $y = y(t) = y(x(t))$. Then you are trying to optimize the action $$ \int_{t_0}^{t_1} \, n\big(x(t),y(t)\big) \, \sqrt{\left(\frac{dx}{dt}(t)\right)^2 + \left(\frac{dy}{dt}(t)\right)^2} dt$$ If you introduce the Riemannian metric $$ds^2 = n(x,y)^2 \, (dx^2 + dy^2) $$ then $$ds = n(x,y) \, \sqrt{dx^2 + dy^2} $$  the   and so your action functional above is $$\int_{(x_0,y_0)}^{(x_1,y_1)} ds = \int_{(x_0,y_0)}^{(x_1,y_1)} \,  n(x,y) \, \sqrt{dx^2 + dy^2} $$  i.e. you are trying to locally minimize the distance between the points $(x_0,y_0)$ and $(x_1,y_1)$ with respect to the Riemannian metric $ds^2 = n(x,y)^2 \, (dx^2 + dy^2) $. So the Euler-Lagrange equations you are interested in (no matter what the parametrization of the curves is) are the geodesics of the metric  $ds^2 = n(x,y)^2 \, (dx^2 + dy^2) $. The latter is a conformal metric. One thing you can do if you care about the solutions and not the form of the equations, is to simplify the situation by trying to minimize the action 
$$\int_{(x_0,y_0)}^{(x_1,y_1)} ds^2 = \int_{(x_0,y_0)}^{(x_1,y_1)} \,  n(x,y)^2 \, \big(dx^2 + dy^2\big) $$ This is kind of like kinetic energy and is going to give you the same trajectories (geodesics). The equations will be simpler I think.
Whether you can explicitly solve this problem depend on $n(x,y)$. For instance if $\log(n(x,y))$ is a harmonic function then the metric $n(x,y)^2 \, \big(dx^2 + dy^2\big)$ is actually flat, meaning that there is a change of variables such that with respect to the new ones this metric becomes the standard flat metric $du^2 + dv^2$. Think of it like this: let any point $(x,y)$ in the plane is written as a complex number $z = x + i \, y$. Then there is a holomorphic (conformal) map $f(z)$ such that 
$$|f'(z)| = n(x,y)$$ Then if $w = u + i \, v$ and $w = f(z)$
$$du^2 + dv^2 = |dw|^2 = |f'(z)|^2 \, |dz|^2 = n(x,y)^2 \, \big(dx^2 + dy^2\big) = ds^2$$
Therefore the geodesics of the metric $ds^2 = n(x,y)^2 \, \big(dx^2 + dy^2\big)$ are mapped by $f(z)$ to the geodesics of the flat metric $du^2 + dv^2$. However, the geodesics of the flat metric are the straight lines. Therefore, if we invert the holomorphic map $w = f(z)$ obtaining $z = f^{-1}(w)$, any straight line  $w = w_0 + t \, \hat{w}$ for $w_0$ and $\hat{w}$ complex numbers and $t \in \mathbb{R}$, the curves $$x(t) + i \, y(t) = z(t) = f^{-1}( w_0 + t \, \hat{w})$$ are the geodesics of the metric $ds^2 = n(x,y)^2 \, \big(dx^2 + dy^2\big)$ which are the solutions to your equation. 
Alternatively, you may have a one parameter group of (relatively nice explicit) symmetries that leave the metric $n(x,y)^2 \, \big(dx^2 + dy^2\big)$ invariant (Noether's theorem) so you may end up finding nice explicit change of variables that transforms the metric into 
$$m(v)^2 \, \big(du^2 + dv^2\big)$$ which may again lead to explicit solutions to your problem. In particular if $$n(x,y) = n(y) = \frac{1}{\sqrt{y}}$$ you end up having the brachistochrone equation, which is solved.
