Hi guys
Wonder if you can help. I'm writing some code to check whether an IP address is within a range of IP addresses.
I have used the following code, however I rekon that the reference to counter "i" is not being resolved and is been taken as a literal i.
the IP address within the table is a string variable not numeric.
Data foo;
set bar;
do i = 97 to 126;
If originatingIPad = 'xx.xxx.xx.&i.' then keep=1;
end;
Run;
Data foobar(drop=keep);
set foo;
where keep=1;
run;
Thanks in advance for any assistance offered.
Jamie
Jamie,
That isn't a macro variable. Try:
Data foo;
set bar;
do i = 97 to 126;
If originatingIPad = 'xx.xxx.xx.'||strip(i) then keep=1;
end;
Run;
Jamie,
That isn't a macro variable. Try:
Data foo;
set bar;
do i = 97 to 126;
If originatingIPad = 'xx.xxx.xx.'||strip(i) then keep=1;
end;
Run;
Do you need to test each value? If you convert to numeric you can test using a range.
data ip;
input ip:$16.;
cards;
000.000.000.123
000.000.000.127
;;;;
run;
proc print;
where 96 le input(scan(ip,-1,'.'),f3.) le 126;
run;
Thanks guys 🙂
I'm glad we were able to help but, the more I think about it, aren't you really going to need something like:
data ip;
length originatingIPad $16;
input originatingIPad;
keep=ifn(97<=scan(originatingIPad,-1,'.')<=126,1,.);
cards;
10.0.0.0
10.0.0.1
10.255.255.96
12.12.12.12
172.16.0.97
172.31.255.255
191.191.191.126
192.168.0.0
192.168.255.127
192.168.255.125
255.255.255.254
255.255.255.255
;
run;
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.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.