DATA xhahhxha 60 3 hahaghagah 10 1 101 xhahhxha 60 3 jrthtahtat 8 1 110 xhahhxha 60 3 shdgehsh 8 1 150 hsghtahs 100 19 hahaghagah 10 20 200 hsghtahs 100 19 jrthtahtat 10 20 300 hsghtahs 100 19 shdgehsh 10 20 400 I want to sort this data such that it outputs a unique string from first column (sorted based on second column value, lowest value string first and its best possible match based on the lowest value in the fifth column and highest value in seventh column (if value in the fifth column is equal). so the output should look like this for the above example: xhahhxha 60 3 shdgehsh 8 1 150 hsghtahs 100 19 shdgehsh 10 20 400