I don't know about nested case-when. The following code seems to be equvalent to your datastep code. proc sql; create table as select *, case when city_code = 100 and Rank_100 in (1,2,3) then '1_3' when city_code = 100 and Rank_100 in (4,5,6) then '4_6' when city_code = 100 and Rank_100 in (7,8,9) then '7_9' when city_code = 100 and Rank_100 not in (1,2,3,4,5,6,7,8,9) then 'NO_Rank' when city_code = 101 and Rank_100 in (1,2,3) then '1_3' when city_code = 101 and Rank_100 in (4,5,6,7,8) then '4_8' when city_code = 101 and Rank_100 in (13,14,15) then '13_15' when city_code = 101 and Rank_100 not in (1,2,3,4,5,6,7,8,13,14,15) then 'NO_Rank' when city_code = 102 and Rank_100 in (20,21,22) then '20_22' when city_code = 102 and Rank_100 in (23,24,25,26) then '23_26' when city_code = 102 and Rank_100 in (27,28,29,30) then '27_30' when city_code = 102 and Rank_100 not in (20,21,22,23,24,25,26,27,28,29,30) then 'NO_Rank' else 'Others' end as Rank_rng length=7 from population_a ; quit; Update: a quick search showing nested case-when is actually supported: http://www.nesug.org/Proceedings/nesug97/posters/zhang.pdf Good Luck, Haikuo
... View more