In the past decade there has been a large scope of studies on mathematical models of social dynamics. Self-organization, i.e., the autonomous formation of patterns, has been so far the main driving concept. Usually first or second order models are considered with given predetermined nonlocal interaction potentials, tuned to reproduce, at least qualitatively, certain global patterns (such as flocks of birds, milling school of fish or line formations in pedestrian flows etc.). However, it is common experience that self-organization of a society does not always spontaneously occur. In the first part of this survey paper we address the question of whether it is possible to externally and parsimoniously influence the dynamics, to promote the formation of certain desired patterns. In particular we address the issue of finding the sparsest control strategy for finite agent models in order to lead the dynamics optimally towards a given outcome. In the second part of the paper we show the rigorous limit process connecting finite dimensional sparse optimal control problems with ODE constraints to an infinite dimensional sparse mean-field optimal control problem with a constraint given by a PDE of Vlasov-type, governing the dynamics of the probability distribution of the agent population. Moreover, often in practice we do not dispose of a precise knowledge of the governing dynamics. In the last part of this paper we present a variational and optimal transport framework leading to an algorithmic solution to the problem of learning the interaction potentials from the observation of the dynamics of a multiagent system.