DATA Step, Macro, Functions and more

Zip code clean up

Reply
Super Contributor
Posts: 647

Zip code clean up


There are some zip codes which have alphabets in them as shown below.I need to display only 08854 as the correct record.regular expressions does this job, but I figure the syntax.

00NSW

W85LJ

08854

Respected Advisor
Posts: 3,124

Re: Zip code clean up

DATA HAVE;

INPUT ZIPCODE $;

IF ANYALPHA(ZIPCODE) THEN DELETE;

CARDS;

00NSW

W85LJ

08854

;

Regards,

Haikuo

Super User
Posts: 10,474

Re: Zip code clean up

Are the data by any chance multinational and you are getting other system postal codes? If so you may want to modifiy Haikuo's suggestion to output the data to two different datasets.


Trusted Advisor
Posts: 2,113

Re: Zip code clean up

You can also use the sashelp.zipcode table to determine if any particular ZIP code is valid.  That data are updated every few months, so you may need to download the current one from sas.com.

Ask a Question
Discussion stats
  • 3 replies
  • 261 views
  • 0 likes
  • 4 in conversation