data ips(drop=i);
* ip to hex to dec process based on
http://www.geocities.com/thestarman3/net/decip.html ;
input ip $15.;
*convert ip to hex;
array i2h_ip{4} 3.;
array i2h_hex{4} $2.;
do i = 1 to 4;
i2h_ip(i) = input(scan(ip,i,'.'),3.);
i2h_hex(i) = put(i2h_ip(i), hex2.);
end;
i2h = cats(i2h_hex1, i2h_hex2, i2h_hex3, i2h_hex4);
*convert hex to dec;
h2d = input(i2h, hex.);
*convert dec back to hex;
d2h = put(h2d, hex8.);
*convert hex back to ip;
array h2i_hex{4} $2.;
array h2i_ip{4} 3.;
do i = 1 to 4;
h2i_hex(i) = substr(d2h, i*2-1, 2);
h2i_ip(i) = input(h2i_hex(i), hex.);
end;
h2i = catx('.',h2i_ip1,h2i_ip2,h2i_ip3,h2i_ip4);
if _n_ = 1 then
put 'IP in' @20 'to Decimal' @40 'back to IP';
put ip @20 h2d @40 h2i;
datalines;
255.255.255.255
209.65.0.0
12.0.0.0
1.0.0.0
run;
LOG
IP in to Decimal back to IP
255.255.255.255 4294967295 255.255.255.255
209.65.0.0 3510697984 209.65.0.0
12.0.0.0 201326592 12.0.0.0
1.0.0.0 16777216 1.0.0.0