x cd /pub/data/georef/Tools; %let pgm=geolite_converts; filename pgm "&pgm..sas"; *---the 2 files downloaded from //www.maxmind.com/app/geolitecity on 12-7-10 contain info related IP addresses to geographic locations. These are the "GeoIP County CVS Text Files". We convert them to SAS datasets and use them to create the idloc permanent sas lookup-table format code. Will use to build a web app to do IP lookups. ---*; filename geoloc '/pub/data/georef/GeoLiteCity-Location.csv'; filename geoblks '/pub/data/georef/GeoLiteCity-Blocks.csv'; libname georef '/pub/data/georef'; libname fmtlib '/pub/sas/catalogs'; libname user '/SAS_temp/userb'; /* ========================begin comment==================================== data georef.geolite_blocks(label='GeoLite City Block Intervals data 12/2010' compress=binary); infile geoblks dsd firstobs=3 ; input startIpnum endIpNum locId; if _n_ le 5 then put _all_; if startIPnum < 0 or StartIpnum gt endIPnum then delete; run; data georef.geolite_city_location(label='GeoLite City Location codes' ); infile geoloc dsd firstobs=3 missover ; length locId 8 country $2 region $2 city $64 ZIP $5 latitude longitude 8 metro AreaCode $3; input locId -- AreaCode; if _n_ le 5 then put _all_; run; proc freq data=georef.geolite_city_location(where=(country='US')); tables country region metro areacode; run; *---And now generate a permanent SAS format code, iploc., that will use a location ID interval as arg and return a string consisting of the state post abbreviation (upper case), the ZIP code and the Cityname ---; proc sort data=georef.geolite_blocks out=args; by locId; run; data cntlin; merge args(in=inargs) georef.geolite_city_location(in=inlocs); by locId; if inargs; if not inlocs then do; _nbad+1; if _nbad le 25 then put '**locId value not found** ' startipnum= endipnum= locid=; else abort abend; delete; end; length Label $80; if country='US' then Label=region||' '||ZIP ||' '||city; else Label='XX Outside US: '||trim(city)||' '||country; retain fmtname 'iploc ' type 'N'; keep startIPnum EndIpNum label fmtname type; rename startIPNum=start endipnum=end; run; proc print data=cntlin (obs=25); title "Sample Obs on cntlin"; run; proc sort data=cntlin; by start; run; data cntlin1 cntlin2 cntlin3 cntlin4; length fmtname $7; set cntlin; if _N_ le 1000000 then do; fmtname='iploc1_'; output cntlin1; end; else if _n_ le 2000000 then do; fmtname='iploc2_'; output cntlin2; end; else if _n_ le 3000000 then do; fmtname='iploc3_'; output cntlin3; end; else do; fmtname='iploc4_'; output cntlin4; end; if mod(_n_,1000000) le 1 then put _all_; run; proc format library=fmtlib cntlin=cntlin1; proc format library=fmtlib cntlin=cntlin2; proc format library=fmtlib cntlin=cntlin3; proc format library=fmtlib cntlin=cntlin4; ==========================end comment====================================== */ proc format library=fmtlib; value iploc 1-1187025919=[iploc1_80.] 1187025920-1547924215=[iploc2_80.] 1547924216-3462302463=[iploc3_80.] 3462302464-high=[iploc4_80.]; run; *---test it----; options fmtsearch=(fmtlib); data _null_; retain ipadd '128.206.61.132'; loc=128*256**3 + 206*256**2 + 61*256 + 132; put loc= loc iploc. ; loc2=3462302463; put loc2= loc2 iploc. +2 loc2 iploc3_. ; run;