How to sort address alphabetically in SAS?


How to sort address alphabetically in SAS?



I have a dataset that has bunch of addresses.


dataset


PROC SORT DATA=work68;
by ADDRESS ;


run;



However it only show ADDRESS columns like .. it considers only the very first number of address..


ADDRESS


2237 Strang Avenue
2932 Ely Avenue
3306 Wilson Ave
3313 Wilson Avenue
3313 Wilson Avenue
3313 Wilson Avenue
46 Nuvern Avenue




3 Answers
3



You can use the option SORTSEQ=LINGUISTIC(NUMERIC_COLLATION=ON) to ask SAS to try and sort numeric values as if they were numbers.


SORTSEQ=LINGUISTIC(NUMERIC_COLLATION=ON)


PROC SORT DATA=work68 sortseq=linguistic(numeric_collation=on);
by ADDRESS ;
run;





how about alphabets in the address??
– juhee Chung
Jul 2 at 4:23





I'm not entirely sure what you're asking? This won't change how the alphabetic characters are sorted.
– Joe
Jul 2 at 4:47






like.. if there are 1107 Ely Avenue and 1111 Huichton Rd. then 1107 Ely Avenue goes first, and then Huichton Rd.
– juhee Chung
Jul 2 at 9:27





I AM asking that .. alphabetically .. not the numbers
– juhee Chung
Jul 2 at 9:37





is there a way to select just street name and sort by the name?
– juhee Chung
Jul 2 at 9:39



If I understand correctly what you're asking, you could try creating a new address column with all digits removed and sort on that:


data have;
input address $100.;
infile cards truncover;
cards;
1107 Huichton Rd.
1111 Ely Avenue
;
run;

data v_have /view = v_have;
set have;
address_nonumbers = strip(compress(address,,'d'));
run;

proc sort data = v_have out = want;
by address_nonumbers;
run;



Proc SQL syntax can sort data in special ways, ORDER BY <computation-1>, …, <computation-N>


ORDER BY <computation-1>, …, <computation-N>



You may want to sort by street names first, and then by numeric premise identifier (house number). For example



Data


data have; input; address=_infile_;datalines;
2237 Strang Avenue
2932 Ely Avenue
3306 Wilson Ave
3313 Wilson Avenue
46 Nuvern Avenue
3313 Ely Avenue
4494 Nuvern Avenue
run;



Sort on street name, then house number


proc sql;
create table want as
select *
from have
order by
compress (address,,'ds') /* ignore digits and spaces - presume to be street name */
, input (scan(address,1),? best12.) /* house number */
;
quit;



This example has simplified presumptions and will not properly sort address constructs such as #### ##th Street


#### ##th Street






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

Display dokan vendor name on Woocommerce single product pages