how about: data population_a; input city_code rank_100; cards; 100 1 100 2 100 4 100 8 101 3 101 6 101 9 102 21 102 26 102 30 ; proc sql; create table temp as select city_code,rank_100, case when city_code=100 then case when rank_100 in (1,2,3) then '1_3' when rank_100 in (4,5,6) then '4_6' when rank_100 in (7,8,9) then '7-9' else 'no_rank' end when city_code=101 then case when rank_100 in (1,2,3) then '1_3' when rank_100 in (4,5,6,7,8) then '4_8' when rank_100 in (13,14,15) then '13-15' else 'no_rank' end else case when rank_100 in (20,21,22) then '20_22' when rank_100 in (23,24,25,26) then '23_26' when rank_100 in (27,28,29,30) then '27_30' else 'no_rank' end end as Rank_rng format=$7. from population_a; quit; proc print;run; Obs code rank_100 Rank_rng 1 100 1 1_3 2 100 2 1_3 3 100 4 4_6 4 100 8 7-9 5 101 3 1_3 6 101 6 4_8 7 101 9 no_rank 8 102 21 20_22 9 102 26 23_26 10 102 30 27_30 Linlin
... View more