turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Distance Calculation

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted
# Distance Calculation

Options

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

a week ago

SAS_M SAS_F

myzip facility_zip

22180 33180

22181 33181

22182 33182

22183 33183

22184 .....

22185 numobs=270 zip codes

22186

22187

22188

22189

22190

.....

.....

.....

numobs=3000 zip codes

SAS_M and SAS_F are two SAS datasets each containing only a column of zip. SAS_M has 3000 rows and SAS_F has 270 rows.

ZIPCITYDISTANCE function works fine for a pair of zips. I need some sort of looping that can do the followings,

ZIPCITYDISTANCE(22180,33180) then

ZIPCITYDISTANCE(22180,33181) then

ZIPCITYDISTANCE(22180,33182) then

ZIPCITYDISTANCE(22180,33183) then

ZIPCITYDISTANCE(22181,33180) then

ZIPCITYDISTANCE(22181,33181) and soforth.

............................

As said the ZIPCITYDISTANCE function works fine when you only have a pair of zips. In my case I need the distance between

first zip from SAS_M to every row of zip in the SAS_F dataset and then the second zip from the SAS_M to every zip rows of

SAS_F dataset and soforth.

Thank you for your help.

* ZIPCITYDISTANCE function;

d1 = zipcitydistance(12203,27513);

Accepted Solutions

Solution

a week ago

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to mauri0623

a week ago

SQL should do it:

```
proc sql;
create table want as
select
a.myzip,
b.facility_zip,
zipcitydistance(a.myzip,b.facility_zip) as distance
from sas_m a, sas_f b;
quit;
```

as it automatically creates a cartesian join.

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

Maxims of Maximally Efficient SAS Programmers

All Replies

Solution

a week ago

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to mauri0623

a week ago

SQL should do it:

```
proc sql;
create table want as
select
a.myzip,
b.facility_zip,
zipcitydistance(a.myzip,b.facility_zip) as distance
from sas_m a, sas_f b;
quit;
```

as it automatically creates a cartesian join.

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

Maxims of Maximally Efficient SAS Programmers

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to KurtBremser

a week ago

Thank you. I will try.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to mauri0623

a week ago

If you need all rows of the second calculated against the rows from the first, them merge 1 to many:

data want; merge myzip (in=a) facility_zip (in=b; if a; diff=zipdistance(myzip,facility_zip); run;

**Note, not tested, post test data in the form of a datastep, and show required output. We are not here to type this in for you!**