- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
it worked. Thanks.