BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Jamie
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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;

View solution in original post

4 REPLIES 4
art297
Opal | Level 21

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;

data_null__
Jade | Level 19

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;

Jamie
Calcite | Level 5

Thanks guys 🙂

art297
Opal | Level 21

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;

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1300 views
  • 3 likes
  • 3 in conversation