BookmarkSubscribeRSS Feed
Adavis
Calcite | Level 5

Hi Everyone,

I am preparing a de-identified version of a dataset. I am required to achieve a minimum of 3 records in each reported geographic area. My original data has zip codes in it, and I'd like to progressively redact digits to reduce the specificity of the zip code data enough to meet the sample size requirements.

For example, if the data look like this:

Zip CodeSample Size

90025

1
900261
900271
90028

1

900294
900302
900311

I would need to group the first four codes together and the last two codes together to get a minimum of 3 observations in each cell. I would do this by stripping off the last digit:

Zip CodeSample Size
9002X4
900294
9003X3

Does anyone have advice on an efficient way to loop through the data to do this? I'm interested in efficiency because my dataset is very large and takes a LONG time to run!

Thank you!

Anna

3 REPLIES 3
ballardw
Super User

What will you do if you have something like this:

90100     10

90101     1

90102     15

Or

90100     1

90101     1

90102     1

90103     8

90104     1

90105     1

90106     1

90107     9

If you truncate to 9010x you have two groups of 3 with the same value.

And do you have any zip+4 codes such as 90100-1234?

Have you previously built a data set with the summary counts for zipcode? Subset the data for those less than 3 and I'd try making a format from that data to see the results.

Also if the resulting code is supposed to imply geographically continguous areas you may have some issues due to some organizations receiving enough mail that the PO will assign them their own Zip code.

Adavis
Calcite | Level 5

Thanks Ballardw!

In the first case, I think I'd "merge" with the (a) geographically more proximal of the two, or (b) the one with the smaller sample size (90100).

In the second case, the two groups of 3 with code 9010X would ultimately be collapsed into a single group with a size of 6, since none of those individual zips can stand alone.

I don't have any zip+4 codes - they are all just straight zips. I used Proc SQL to build the summary dataset, and could definitely start by sub-setting to just those zips that are going to be a problem. I am a little concerned about the geographic contiguity issue, but I don't really know how to best deal with it. I'm sure there's some way to write a script that can preferentially merge proximal areas, but I don't know how to do that.

ballardw
Super User

The zipcode contiguity issue may be solved using Zipcitydistance function to give you a distance between likely candidates and then pick the closest.

Or possible look at the clustering procedures using that distance OR bring in the latitude and longitude from the sashelp.zipcode data set and use the x y for clustering.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 3 replies
  • 548 views
  • 3 likes
  • 2 in conversation