proc sort data=sashelp.zipcode out=ByZIP; where StateName="Delaware" and CountyNm="New Castle"; by ZIP; run; data grouped; set ByZIP; if City ne lag(City) then Group+1; run; proc print data=grouped(obs=30); by Group City; id Group City; var ZIP Alias_City; title1 "ZIP Codes Grouped by City"; run;