BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Test_yes
Calcite | Level 5

I have 3 million records which have zip code as one of the entities. I need to validate whether they are valid zip codes are not.

I have the set of valid zip codes from sashelp.zipcode. Which is the best way to validate my data? Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
jagadeeshp
Fluorite | Level 6
Hello,
Hope this below snippet works for you.
 
proc sql;
create table final as
select
a.*,
b.zip as Zip2

from
customer a

left join
sashelp.zipcode b
on a.ZIP = b.ZIP
;
quit;
Assuming the CUSTOMER table as a dataset which contains the invalid zip codes. If we left join the sashelp.zipcode to our CUSTOMER table and selecting the ZIP (as ZIP2) from sashelp.zipcode would leave the invalid ZIP with missing values (Since it SAS cannot find the matching value)
 
data
final(
drop=zip
rename=(zip2=zip)
);
set
final
;
run;
In the above snippet we will drop the ZIP field with invalid codes and Rename the ZIP2 to ZIP(which obviously have the Invalid zip codes as '.')
 

Note: the above code is written based on the assumption that the Zip code is 5 digit.

View solution in original post

4 REPLIES 4
ballardw
Super User

Depends on what you want. Do you want to mark a records a finding a match in the data set? Or that the Zipcode matches a state or city value that you have as well?

 

It will help if you show what you want to see for "valid" and "invalid" zip codes.

 

And are your zipcodes all 5 digit or do you have some Zip+4 codes?

Test_yes
Calcite | Level 5

I want to keep the zip code only if it is valid in my dataset by validating against the look up file. If a particular zip is invalid I need to have null in my dataset for that row.

jagadeeshp
Fluorite | Level 6
Hello,
Hope this below snippet works for you.
 
proc sql;
create table final as
select
a.*,
b.zip as Zip2

from
customer a

left join
sashelp.zipcode b
on a.ZIP = b.ZIP
;
quit;
Assuming the CUSTOMER table as a dataset which contains the invalid zip codes. If we left join the sashelp.zipcode to our CUSTOMER table and selecting the ZIP (as ZIP2) from sashelp.zipcode would leave the invalid ZIP with missing values (Since it SAS cannot find the matching value)
 
data
final(
drop=zip
rename=(zip2=zip)
);
set
final
;
run;
In the above snippet we will drop the ZIP field with invalid codes and Rename the ZIP2 to ZIP(which obviously have the Invalid zip codes as '.')
 

Note: the above code is written based on the assumption that the Zip code is 5 digit.
Test_yes
Calcite | Level 5

it worked. Thanks.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1481 views
  • 0 likes
  • 3 in conversation