LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (June 2009)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 2 Jun 2009 01:00:27 -0700
Reply-To:     djhurio <martins.liberts@gmail.com>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         djhurio <martins.liberts@gmail.com>
Subject:      Re: matching data files
In-Reply-To:  <7.0.1.0.2.20090601171904.03402cd0@mindspring.com>
Content-Type: text/plain; charset=us-ascii

OK, here is a complete solution.

I am assuming that IP ranges are not overlapping. IP2 is a sortable IP address. IPRangeID is 0 for IPs out of any range defined and 1,2,3... for other IPs in ranges.

HTH.

P.S. I have used many EXECUTE commands because of the lag() functions.

cd "C:\TEMP\SPSS".

***.

data list free /IP (a15). begin data 1.2.3.4 123.456.78.0 123.456.78.2 123.456.100.4 123.456.123.12 999.7.7.7 end data.

save out "data_IP.sav".

***.

data list free /IPStart (a15) IPEnd (a15) Location (a1). begin data 123.456.77.1 123.456.78.99 A 123.456.122.0 123.456.123.50 B end data.

save out "data_Loc.sav".

***.

add files /file "data_Loc.sav" /ren IPStart=IP /in start /file "data_Loc.sav" /ren IPEnd=IP /in end /file "data_IP.sav" /in data /drop IPEND IPStart.

string IP2 (a15). string #temp (a12).

comp IP2=str(num(sub(IP,1,index(IP,".")-1),f3),n3). comp #temp=con(sub(IP,index(IP,".")+1),".").

loop #k=1 to 3. comp IP2=con(rtr(IP2),".",str(num(sub(#temp,1,index(#temp,".")-1),f3),n3)). comp #temp=sub(#temp,index(#temp,".")+1). end loop.

sort cases IP2.

do if start. comp #counter=sum(lag(#counter),1). else. comp #counter=sum(lag(#counter),0). end if.

do if start. comp IPRangeID=#counter. else if ~start and (lag(end) or $casenum=1). comp IPRangeID=0. else. comp IPRangeID=lag(IPRangeID). end if.

exe.

if data and IPRangeID>0 Location=lag(Location).

exe.

string IPStart IPEnd (a15).

do if start. comp IPStart=IP. else if IPRangeID>0. comp IPStart=lag(IPStart). else. comp IPStart="". end if.

exe.

sort cases IP2 (d).

do if end. comp IPEnd=IP. else if IPRangeID>0. comp IPEnd=lag(IPEnd). else. comp IPEnd="". end if.

exe.

sort cases IP2.

sel if data.

exe.

del var start end data IP2.

Richard Ristow wrote: > > At 02:17 PM 6/1/2009, Gene Maguin wrote: > >>I'm just pretty sure that this problem has come up before > > The problem of matching a key to a range does come up from time to > time, most commonly where the keys are dates. I've posted on it, but > I can't find where, now. > > I think djhurio's approach is essentially the right one, including > addressing the question of building a sortable form of the IP > addresses. Have you got it to work, or do you still have questions? > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD > >

-- View this message in context: http://www.nabble.com/matching-data-files-tp23812321p23827731.html Sent from the SPSSX Discussion mailing list archive at Nabble.com.

===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD


Back to: Top of message | Previous page | Main SPSSX-L page