You want
"IF i have a data like this and i want to calculate top 2 state based upon max population and along with its top 5 cities,how would i do it?"
By top 2 states, I presume you intend to total up population for all cities within each state, and take the 2 largest states. And from there, you want the largest 5 cities in each of those states, right? If so, proc rank won't work until you select the states.
Consider proc summary as a way to generate state totals in a summary data set. Then choose the two largest totals and merge that with your city dataset based on the state identifier. You could then run a proc rank, to produce city ranks within state, and filter out cities without a qualifying city rank.
BTW, what if you have ties in state totals or city populations?
... View more