Useful SAS functions for Zip Code and Geo Distance

 Author: Prateek Paatni


Plotting information on the map is one of the powerful visualization. Plotting on a map require latitude and longitude information of a place.

For country level longitude and latitude information, one can refer a compiled country level information on the CountryISOCode,latitude and longitude

One can refer Country level Heatmap which is plotted using R for a visualization example.

SAS also provides a lot of proceduces for visualizations. Considering a lot of challenges in the data availability and plotting requirements, SAS has created a zip code level information for United States (US).

Read more

Market Basket Analysis – Step by Step Approach using R

First Published at DnI Institute

Market Basket Analysis (MBA) is one of the commonly used analytical framework in Retail Industry. It can very well be leveraged in other industries and applications.

Some of the key questions Market Basket Analysis (MBA) tries to answer are

  • Should we perform market basket analysis at a product level or category level?
  • Do we have information on sequence of products buying in a basket or customer visit?
  • Which are products bought together by the customers?
  • Can we conclude if product ‘A’ sale drives product ‘B’ sales?
  • What product categories are bought together?
  • What product is to be recommended given a customer has bought a product or a group of products?

Read More: Market Basket Analysis Step By Step

Customer Life Cycle and Customer Retention Management

Customer Life Cycle

Customer Acquisition: Focus is targeting & reaching out to prospects, explaining them about the products and services and on-boarding the customers.
Customer Development/Build/Growth: In this phase organizations leverage the existing relationship for growing the engagement with newly acquired customers or existing customers. So, the focus is both on increasing level of engagement on the existing product or relationship (i.e. spend/balance build on credit card) and identifying customers’ needs & soliciting for a right product (i.e. cross sell a credit card to mortgage customers).

Customer Retention: The most valuable customers are the most sought after customers by the competitors. The organizations have to develop strategies to manage and retain the most valuable customers. Acquiring a new customer is 3-5 times more costly, but still organizations are finding difficult to retain their customers….Read more

Country latitude and Longitude





Objective of this blog is really simple, share a formatted and clean data on Country Name, ISO Code and Latitute and Longitude. These infornation is required for global map plotting and I could not get at one place.

Also we will use R Visualization to show the data on the map.

Read Data

# Set up library
setwd("C:/Ram/Learn R/training")
# Read Data
CountryGeo <- read.csv("CountryGeoInfo.csv")
rownames(CountryGeo) <- NULL
options(width=120)
print(CountryGeo)
##                                      CountryName CountryISOCode latitude longitude
## 1                                    AFGHANISTAN             AF  33.0000    65.000
## 2                                  ÅLAND ISLANDS             AX  12.5000   -69.967
## 3                                        ALBANIA             AL  41.0000    20.000
## 4                                        ALGERIA             DZ  28.0000     3.000
## 5                                 AMERICAN SAMOA             AS -14.3333  -170.000
## 6                                        ANDORRA             AD  42.5000     1.500
## 7                                         ANGOLA             AO -12.5000    18.500
## 8                                       ANGUILLA             AI  18.2500   -63.167
## 9                                     ANTARCTICA             AQ -90.0000     0.000
## 10                           ANTIGUA AND BARBUDA             AG  17.0500   -61.800
## 11                                     ARGENTINA             AR -34.0000   -64.000
## 12                                       ARMENIA             AM  40.0000    45.000
## 13                                         ARUBA             AW  12.5000   -69.967
## 14                                     AUSTRALIA             AU -27.0000   133.000
## 15                                       AUSTRIA             AT  47.3333    13.333
## 16                                    AZERBAIJAN             AZ  40.5000    47.500
## 17                                       BAHAMAS             BS  24.2500   -76.000
## 18                                       BAHRAIN             BH  26.0000    50.550
## 19                                    BANGLADESH             BD  24.0000    90.000
## 20                                      BARBADOS             BB  13.1667   -59.533
## 21                                       BELARUS             BY  53.0000    28.000
## 22                                       BELGIUM             BE  50.8333     4.000
## 23                                        BELIZE             BZ  17.2500   -88.750
## 24                                         BENIN             BJ   9.5000     2.250
## 25                                       BERMUDA             BM  32.3333   -64.750
## 26                                        BHUTAN             BT  27.5000    90.500
## 27               BOLIVIA, PLURINATIONAL STATE OF             BO -17.0000   -65.000
## 28              BONAIRE, SINT EUSTATIUS AND SABA             BQ -17.0000   -65.000
## 29                        BOSNIA AND HERZEGOVINA             BA  44.0000    18.000
## 30                                      BOTSWANA             BW -22.0000    24.000
## 31                                 BOUVET ISLAND             BV -54.4333     3.400
## 32                                        BRAZIL             BR -10.0000   -55.000
## 33                BRITISH INDIAN OCEAN TERRITORY             IO  -6.0000    71.500
## 34                             BRUNEI DARUSSALAM             BN   4.5000   114.667
## 35                                      BULGARIA             BG  43.0000    25.000
## 36                                  BURKINA FASO             BF  13.0000    -2.000
## 37                                       BURUNDI             BI  -3.5000    30.000
## 38                                      CAMBODIA             KH  13.0000   105.000
## 39                                      CAMEROON             CM   6.0000    12.000
## 40                                        CANADA             CA  60.0000   -95.000
## 41                                    CAPE VERDE             CV  16.0000   -24.000
## 42                                CAYMAN ISLANDS             KY  19.5000   -80.500
## 43                      CENTRAL AFRICAN REPUBLIC             CF   7.0000    21.000
## 44                                          CHAD             TD  15.0000    19.000
## 45                                         CHILE             CL -30.0000   -71.000
## 46                                         CHINA             CN  35.0000   105.000
## 47                              CHRISTMAS ISLAND             CX -10.5000   105.667
## 48                       COCOS (KEELING) ISLANDS             CC -12.5000    96.833
## 49                                      COLOMBIA             CO   4.0000   -72.000
## 50                                       COMOROS             KM -12.1667    44.250
## 51                                         CONGO             CG  -1.0000    15.000
## 52         CONGO, THE DEMOCRATIC REPUBLIC OF THE             CD   0.0000    25.000
## 53                                  COOK ISLANDS             CK -21.2333  -159.767
## 54                                    COSTA RICA             CR  10.0000   -84.000
## 55                                 CÔTE D'IVOIRE             CI   8.0000    -5.000
## 56                                       CROATIA             HR  45.1667    15.500
## 57                                          CUBA             CU  21.5000   -80.000
## 58                                       CURAÇAO             CW  16.0000   -24.000
## 59                                        CYPRUS             CY  35.0000    33.000
## 60                                CZECH REPUBLIC             CZ  49.7500    15.500
## 61                                       DENMARK             DK  56.0000    10.000
## 62                                      DJIBOUTI             DJ  11.5000    43.000
## 63                                      DOMINICA             DM  15.4167   -61.333
## 64                            DOMINICAN REPUBLIC             DO  19.0000   -70.667
## 65                                       ECUADOR             EC  -2.0000   -77.500
## 66                                         EGYPT             EG  27.0000    30.000
## 67                                   EL SALVADOR             SV  13.8333   -88.917
## 68                             EQUATORIAL GUINEA             GQ   2.0000    10.000
## 69                                       ERITREA             ER  15.0000    39.000
## 70                                       ESTONIA             EE  59.0000    26.000
## 71                                      ETHIOPIA             ET   8.0000    38.000
## 72                   FALKLAND ISLANDS (MALVINAS)             FK -51.7500   -59.000
## 73                                 FAROE ISLANDS             FO  62.0000    -7.000
## 74                                          FIJI             FJ -18.0000   175.000
## 75                                       FINLAND             FI  64.0000    26.000
## 76                                        FRANCE             FR  46.0000     2.000
## 77                                 FRENCH GUIANA             GF   4.0000   -53.000
## 78                              FRENCH POLYNESIA             PF -15.0000  -140.000
## 79                   FRENCH SOUTHERN TERRITORIES             TF -43.0000    67.000
## 80                                         GABON             GA  -1.0000    11.750
## 81                                        GAMBIA             GM  13.4667   -16.567
## 82                                       GEORGIA             GE  42.0000    43.500
## 83                                       GERMANY             DE  51.0000     9.000
## 84                                         GHANA             GH   8.0000    -2.000
## 85                                     GIBRALTAR             GI  36.1833    -5.367
## 86                                        GREECE             GR  39.0000    22.000
## 87                                     GREENLAND             GL  72.0000   -40.000
## 88                                       GRENADA             GD  12.1167   -61.667
## 89                                    GUADELOUPE             GP  16.2500   -61.583
## 90                                          GUAM             GU  13.4667   144.783
## 91                                     GUATEMALA             GT  15.5000   -90.250
## 92                                      GUERNSEY             GG   4.0000   -53.000
## 93                                        GUINEA             GN  11.0000   -10.000
## 94                                 GUINEA-BISSAU             GW  12.0000   -15.000
## 95                                        GUYANA             GY   5.0000   -59.000
## 96                                         HAITI             HT  19.0000   -72.417
## 97             HEARD ISLAND AND MCDONALD ISLANDS             HM -53.1000    72.517
## 98                 HOLY SEE (VATICAN CITY STATE)             VA  41.9000    12.450
## 99                                      HONDURAS             HN  15.0000   -86.500
## 100                                    HONG KONG             HK  22.2500   114.167
## 101                                      HUNGARY             HU  47.0000    20.000
## 102                                      ICELAND             IS  65.0000   -18.000
## 103                                        INDIA             IN  20.0000    77.000
## 104                                    INDONESIA             ID  -5.0000   120.000
## 105                    IRAN, ISLAMIC REPUBLIC OF             IR  32.0000    53.000
## 106                                         IRAQ             IQ  33.0000    44.000
## 107                                      IRELAND             IE  53.0000    -8.000
## 108                                  ISLE OF MAN             IM  31.5000    34.750
## 109                                       ISRAEL             IL  31.5000    34.750
## 110                                        ITALY             IT  42.8333    12.833
## 111                                      JAMAICA             JM  18.2500   -77.500
## 112                                        JAPAN             JP  36.0000   138.000
## 113                                       JERSEY             JE  42.8333    12.833
## 114                                       JORDAN             JO  31.0000    36.000
## 115                                   KAZAKHSTAN             KZ  48.0000    68.000
## 116                                        KENYA             KE   1.0000    38.000
## 117                                     KIRIBATI             KI   1.4167   173.000
## 118       KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF             KP  40.0000   127.000
## 119                           KOREA, REPUBLIC OF             KR  37.0000   127.500
## 120                                       KUWAIT             KW  29.3375    47.658
## 121                                   KYRGYZSTAN             KG  41.0000    75.000
## 122             LAO PEOPLE'S DEMOCRATIC REPUBLIC             LA  18.0000   105.000
## 123                                       LATVIA             LV  57.0000    25.000
## 124                                      LEBANON             LB  33.8333    35.833
## 125                                      LESOTHO             LS -29.5000    28.500
## 126                                      LIBERIA             LR   6.5000    -9.500
## 127                                        LIBYA             LY  25.0000    17.000
## 128                                LIECHTENSTEIN             LI  47.1667     9.533
## 129                                    LITHUANIA             LT  56.0000    24.000
## 130                                   LUXEMBOURG             LU  49.7500     6.167
## 131                                        MACAO             MO  22.1667   113.550
## 132   MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF             MK  41.8333    22.000
## 133                                   MADAGASCAR             MG -20.0000    47.000
## 134                                       MALAWI             MW -13.5000    34.000
## 135                                     MALAYSIA             MY   2.5000   112.500
## 136                                     MALDIVES             MV   3.2500    73.000
## 137                                         MALI             ML  17.0000    -4.000
## 138                                        MALTA             MT  35.8333    14.583
## 139                             MARSHALL ISLANDS             MH   9.0000   168.000
## 140                                   MARTINIQUE             MQ  14.6667   -61.000
## 141                                   MAURITANIA             MR  20.0000   -12.000
## 142                                    MAURITIUS             MU -20.2833    57.550
## 143                                      MAYOTTE             YT -12.8333    45.167
## 144                                       MEXICO             MX  23.0000  -102.000
## 145              MICRONESIA, FEDERATED STATES OF             FM   6.9167   158.250
## 146                         MOLDOVA, REPUBLIC OF             MD  47.0000    29.000
## 147                                       MONACO             MC  43.7333     7.400
## 148                                     MONGOLIA             MN  46.0000   105.000
## 149                                   MONTENEGRO             ME  42.0000    19.000
## 150                                   MONTSERRAT             MS  16.7500   -62.200
## 151                                      MOROCCO             MA  32.0000    -5.000
## 152                                   MOZAMBIQUE             MZ -18.2500    35.000
## 153                                      MYANMAR             MM  22.0000    98.000
## 154                                      NAMIBIA           <NA> -22.0000    17.000
## 155                                        NAURU             NR  -0.5333   166.917
## 156                                        NEPAL             NP  28.0000    84.000
## 157                                  NETHERLANDS             NL  52.5000     5.750
## 158                                NEW CALEDONIA             NC -21.5000   165.500
## 159                                  NEW ZEALAND             NZ -41.0000   174.000
## 160                                    NICARAGUA             NI  13.0000   -85.000
## 161                                        NIGER             NE  16.0000     8.000
## 162                                      NIGERIA             NG  10.0000     8.000
## 163                                         NIUE             NU -19.0333  -169.867
## 164                               NORFOLK ISLAND             NF -29.0333   167.950
## 165                     NORTHERN MARIANA ISLANDS             MP  15.2000   145.750
## 166                                       NORWAY             NO  62.0000    10.000
## 167                                         OMAN             OM  21.0000    57.000
## 168                                     PAKISTAN             PK  30.0000    70.000
## 169                                        PALAU             PW   7.5000   134.500
## 170                          PALESTINE, STATE OF             PS  32.0000    35.250
## 171                                       PANAMA             PA   9.0000   -80.000
## 172                             PAPUA NEW GUINEA             PG  -6.0000   147.000
## 173                                     PARAGUAY             PY -23.0000   -58.000
## 174                                         PERU             PE -10.0000   -76.000
## 175                                  PHILIPPINES             PH  13.0000   122.000
## 176                                     PITCAIRN             PN  46.8333   -56.333
## 177                                       POLAND             PL  52.0000    20.000
## 178                                     PORTUGAL             PT  39.5000    -8.000
## 179                                  PUERTO RICO             PR  18.2500   -66.500
## 180                                        QATAR             QA  25.5000    51.250
## 181                                      RÉUNION             RE -21.1000    55.600
## 182                                      ROMANIA             RO  46.0000    25.000
## 183                           RUSSIAN FEDERATION             RU  60.0000   100.000
## 184                                       RWANDA             RW  -2.0000    30.000
## 185                             SAINT BARTHÉLEMY             BL   9.5000     2.250
## 186 SAINT HELENA, ASCENSION AND TRISTAN DA CUNHA             SH -15.9333    -5.700
## 187                        SAINT KITTS AND NEVIS             KN  17.3333   -62.750
## 188                                  SAINT LUCIA             LC  13.8833   -61.133
## 189                   SAINT MARTIN (FRENCH PART)             MF  42.0000    19.000
## 190                    SAINT PIERRE AND MIQUELON             PM  46.8333   -56.333
## 191             SAINT VINCENT AND THE GRENADINES             VC  13.2500   -61.200
## 192                                        SAMOA             WS -13.5833  -172.333
## 193                                   SAN MARINO             SM  43.7667    12.417
## 194                        SAO TOME AND PRINCIPE             ST   1.0000     7.000
## 195                                 SAUDI ARABIA             SA  25.0000    45.000
## 196                                      SENEGAL             SN  14.0000   -14.000
## 197                                       SERBIA             RS  44.0000    21.000
## 198                                   SEYCHELLES             SC  -4.5833    55.667
## 199                                 SIERRA LEONE             SL   8.5000   -11.500
## 200                                    SINGAPORE             SG   1.3667   103.800
## 201                    SINT MAARTEN (DUTCH PART)             SX  13.8333   -88.917
## 202                                     SLOVAKIA             SK  48.6667    19.500
## 203                                     SLOVENIA             SI  46.0000    15.000
## 204                              SOLOMON ISLANDS             SB  -8.0000   159.000
## 205                                      SOMALIA             SO  10.0000    49.000
## 206                                 SOUTH AFRICA             ZA -29.0000    24.000
## 207 SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS             GS -54.5000   -37.000
## 208                                  SOUTH SUDAN             SS   4.0000   -56.000
## 209                                        SPAIN             ES  40.0000    -4.000
## 210                                    SRI LANKA             LK   7.0000    81.000
## 211                                        SUDAN             SD  15.0000    30.000
## 212                                     SURINAME             SR   4.0000   -56.000
## 213                       SVALBARD AND JAN MAYEN             SJ  78.0000    20.000
## 214                                    SWAZILAND             SZ -26.5000    31.500
## 215                                       SWEDEN             SE  62.0000    15.000
## 216                                  SWITZERLAND             CH  47.0000     8.000
## 217                         SYRIAN ARAB REPUBLIC             SY  35.0000    38.000
## 218                    TAIWAN, PROVINCE OF CHINA             TW  23.5000   121.000
## 219                                   TAJIKISTAN             TJ  39.0000    71.000
## 220                 TANZANIA, UNITED REPUBLIC OF             TZ  -6.0000    35.000
## 221                                     THAILAND             TH  15.0000   100.000
## 222                                  TIMOR-LESTE             TL  -9.0000  -172.000
## 223                                         TOGO             TG   8.0000     1.167
## 224                                      TOKELAU             TK  -9.0000  -172.000
## 225                                        TONGA             TO -20.0000  -175.000
## 226                          TRINIDAD AND TOBAGO             TT  11.0000   -61.000
## 227                                      TUNISIA             TN  34.0000     9.000
## 228                                       TURKEY             TR  39.0000    35.000
## 229                                 TURKMENISTAN             TM  40.0000    60.000
## 230                     TURKS AND CAICOS ISLANDS             TC  21.7500   -71.583
## 231                                       TUVALU             TV  -8.0000   178.000
## 232                                       UGANDA             UG   1.0000    32.000
## 233                                      UKRAINE             UA  49.0000    32.000
## 234                         UNITED ARAB EMIRATES             AE  24.0000    54.000
## 235                               UNITED KINGDOM             GB  54.0000    -2.000
## 236                                UNITED STATES             US  38.0000   -97.000
## 237         UNITED STATES MINOR OUTLYING ISLANDS             UM  19.2833   166.600
## 238                                      URUGUAY             UY -33.0000   -56.000
## 239                                   UZBEKISTAN             UZ  41.0000    64.000
## 240                                      VANUATU             VU -16.0000   167.000
## 241            VENEZUELA, BOLIVARIAN REPUBLIC OF             VE   8.0000   -66.000
## 242                                     VIET NAM             VN  16.0000   106.000
## 243                      VIRGIN ISLANDS, BRITISH             VG  18.5000   -64.500
## 244                         VIRGIN ISLANDS, U.S.             VI  18.3333   -64.833
## 245                            WALLIS AND FUTUNA             WF -13.3000  -176.200
## 246                               WESTERN SAHARA             EH  24.5000   -13.000
## 247                                        YEMEN             YE  15.0000    48.000
## 248                                       ZAMBIA             ZM -15.0000    30.000
## 249                                     ZIMBABWE             ZW -20.0000    30.000