Step 1: Recognize the form of the equation
The equation $\left( x \sin \frac{y}{x} \right) \frac{dy}{dx} = y \sin \frac{y}{x} - x$ is homogeneous. Let $v = \frac{y}{x}$, so $y = vx$, $\frac{dy}{dx} = v + x \frac{dv}{dx}$. Substitute: $\left( x \sin v \right) \left( v + x \frac{dv}{dx} \right) = (vx) \sin v - x$, simplify: $x \sin v \cdot x \frac{dv}{dx} = -x$, $\sin v \frac{dv}{dx} = -\frac{1}{x}$.
Step 2: Solve the separated equation
$\sin v \, dv = -\frac{dx}{x}$, integrate: $-\cos v = -\log x + c$, $\log x - \cos v = c$. Substitute back: $\log x - \cos \frac{y}{x} = c$.
Step 3: Match with options
The solution $\log x - \cos \frac{y}{x} = c$ matches option (4).