From: Ya Huang on
Nice!!

I've never noticed the use of Char() function. Is this from v9?

Thanks.

Ya

On Fri, 26 Feb 2010 14:41:38 -0500, Mike Zdeb <msz03(a)ALBANY.EDU> wrote:

>hi ... another idea ...
>
>data x;
>iphx='99aa2233'x;
>ip = catx('.',rank(char(iphx,1)),rank(char(iphx,2)),rank(char(iphx,3)),rank
(char(iphx,4)));
>put 'IP: ' ip;
>run;
>
>IP: 153.170.34.51
>
>
>
>
>--
>Mike Zdeb
>U(a)Albany School of Public Health
>One University Place
>Rensselaer, New York 12144-3456
>P/518-402-6479 F/630-604-1475
>
>> Then use $hex. format to convert it first:
>>
>> 151 data _null_;
>> 152 iphx='99aa2233'x;
>> 153 iphxc=put(iphx,$hex.);
>> 154 ipdec1=put(input(substr(iphxc,1,2),hex.),best.);
>> 155 ipdec2=put(input(substr(iphxc,3,2),hex.),best.);
>> 156 ipdec3=put(input(substr(iphxc,5,2),hex.),best.);
>> 157 ipdec4=put(input(substr(iphxc,7,2),hex.),best.);
>> 158 ipdec=compress(ipdec1||'.'||ipdec2||'.'||ipdec3||'.'||ipdec4);
>> 159 put ipdec;
>> 160 run;
>>
>> 153.170.34.51
>>
>>
>> On Fri, 26 Feb 2010 13:34:42 -0500, Jack Kelly
>> <John_J_Kelly(a)AO.USCOURTS.GOV> wrote:
>>
>>><snip>
>>>Yes, use scan,input,put can do it:
>>>
>>>1 data _null_;
>>>2 iphx='0xC0.0x00.0x02.0xEB';
>>>3 ipdec1=put(input(scan(scan(iphx,1,'.'),2,'x'),hex.),best.);
>>></snip>
>>>
>>>My mistake and thanks for the reply. I should have stated that the number
>>>is hex with no dots, e.g. x'99aa2233'. It is an IBM format that they use
>>>in most of their accounting type data. So I can't see how I can SCAN and
>>>SUBSTR[N] only seems to work well with characters.
>>
From: Mike Zdeb on
hi ... another idea ...

data x;
iphx='99aa2233'x;
ip = catx('.',rank(char(iphx,1)),rank(char(iphx,2)),rank(char(iphx,3)),rank(char(iphx,4)));
put 'IP: ' ip;
run;

IP: 153.170.34.51




--
Mike Zdeb
U(a)Albany School of Public Health
One University Place
Rensselaer, New York 12144-3456
P/518-402-6479 F/630-604-1475

> Then use $hex. format to convert it first:
>
> 151 data _null_;
> 152 iphx='99aa2233'x;
> 153 iphxc=put(iphx,$hex.);
> 154 ipdec1=put(input(substr(iphxc,1,2),hex.),best.);
> 155 ipdec2=put(input(substr(iphxc,3,2),hex.),best.);
> 156 ipdec3=put(input(substr(iphxc,5,2),hex.),best.);
> 157 ipdec4=put(input(substr(iphxc,7,2),hex.),best.);
> 158 ipdec=compress(ipdec1||'.'||ipdec2||'.'||ipdec3||'.'||ipdec4);
> 159 put ipdec;
> 160 run;
>
> 153.170.34.51
>
>
> On Fri, 26 Feb 2010 13:34:42 -0500, Jack Kelly
> <John_J_Kelly(a)AO.USCOURTS.GOV> wrote:
>
>><snip>
>>Yes, use scan,input,put can do it:
>>
>>1 data _null_;
>>2 iphx='0xC0.0x00.0x02.0xEB';
>>3 ipdec1=put(input(scan(scan(iphx,1,'.'),2,'x'),hex.),best.);
>></snip>
>>
>>My mistake and thanks for the reply. I should have stated that the number
>>is hex with no dots, e.g. x'99aa2233'. It is an IBM format that they use
>>in most of their accounting type data. So I can't see how I can SCAN and
>>SUBSTR[N] only seems to work well with characters.
>
From: Mike Zdeb on
hi ... it's V9 I guess (I know that it's in 9.1.3)

the other question, why CHAR when we already have SUBSTR

well ... one difference is that with SUBSTR, the default length of the result is the length of the variable used
regardless of how many characters are extracted while with CHAR, the length of the result is always 1

another is what happens in the LOG if the start location specified is incorrect ...


data x;
name = 'HUANG';
f_char = char(name,1);
f_substr = substr(name,1);

mistake0_char = char(name,0);
mistake0_substr = substr(name,0);

mistake10_char = char(name,10);
mistake10_substr = substr(name,10);
run;

proc contents data=x;
run;

the LOG ... no messages with CHAR ...

899 data x;
900 name = 'HUANG';
901 f_char = char(name,1);
902 f_substr = substr(name,1);
903
904 mistake0_char = char(name,0);
905 mistake0_substr = substr(name,0);
906
907 mistake10_char = char(name,10);
908 mistake10_substr = substr(name,10);
909 run;

NOTE: Invalid second argument to function SUBSTR at line 905 column 19.
NOTE: Invalid second argument to function SUBSTR at line 908 column 20.
name=HUANG f_char=H f_substr=HUANG mistake0_char= mistake0_substr= mistake10_char= mistake10_substr= _ERROR_=1 _N_=1
NOTE: The data set WORK.X has 1 observations and 7 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds


the OUTPUT ...

# Variable Type Len
2 f_char Char 1
3 f_substr Char 5
4 mistake0_char Char 1
5 mistake0_substr Char 5
6 mistake10_char Char 1
7 mistake10_substr Char 5
1 name Char 5






--
Mike Zdeb
U(a)Albany School of Public Health
One University Place
Rensselaer, New York 12144-3456
P/518-402-6479 F/630-604-1475

> Nice!!
>
> I've never noticed the use of Char() function. Is this from v9?
>
> Thanks.
>
> Ya
>
> On Fri, 26 Feb 2010 14:41:38 -0500, Mike Zdeb <msz03(a)ALBANY.EDU> wrote:
>
>>hi ... another idea ...
>>
>>data x;
>>iphx='99aa2233'x;
>>ip = catx('.',rank(char(iphx,1)),rank(char(iphx,2)),rank(char(iphx,3)),rank
> (char(iphx,4)));
>>put 'IP: ' ip;
>>run;
>>
>>IP: 153.170.34.51
>>
>>
>>
>>
>>--
>>Mike Zdeb
>>U(a)Albany School of Public Health
>>One University Place
>>Rensselaer, New York 12144-3456
>>P/518-402-6479 F/630-604-1475
>>
>>> Then use $hex. format to convert it first:
>>>
>>> 151 data _null_;
>>> 152 iphx='99aa2233'x;
>>> 153 iphxc=put(iphx,$hex.);
>>> 154 ipdec1=put(input(substr(iphxc,1,2),hex.),best.);
>>> 155 ipdec2=put(input(substr(iphxc,3,2),hex.),best.);
>>> 156 ipdec3=put(input(substr(iphxc,5,2),hex.),best.);
>>> 157 ipdec4=put(input(substr(iphxc,7,2),hex.),best.);
>>> 158 ipdec=compress(ipdec1||'.'||ipdec2||'.'||ipdec3||'.'||ipdec4);
>>> 159 put ipdec;
>>> 160 run;
>>>
>>> 153.170.34.51
>>>
>>>
>>> On Fri, 26 Feb 2010 13:34:42 -0500, Jack Kelly
>>> <John_J_Kelly(a)AO.USCOURTS.GOV> wrote:
>>>
>>>><snip>
>>>>Yes, use scan,input,put can do it:
>>>>
>>>>1 data _null_;
>>>>2 iphx='0xC0.0x00.0x02.0xEB';
>>>>3 ipdec1=put(input(scan(scan(iphx,1,'.'),2,'x'),hex.),best.);
>>>></snip>
>>>>
>>>>My mistake and thanks for the reply. I should have stated that the number
>>>>is hex with no dots, e.g. x'99aa2233'. It is an IBM format that they use
>>>>in most of their accounting type data. So I can't see how I can SCAN and
>>>>SUBSTR[N] only seems to work well with characters.
>>>
>
From: Nathaniel Wooding on
Mike

I just tried running it in 8.2 and the function was not recognized. It does not appear in TS486 nor is it documented in 9.1.3 even though it appears to be recognized there. It is documented in 9.2.

Nat

-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] On Behalf Of Mike Zdeb
Sent: Friday, February 26, 2010 3:19 PM
To: SAS-L(a)LISTSERV.UGA.EDU
Subject: Re: How to - Hex IP address to dotted decimal

hi ... it's V9 I guess (I know that it's in 9.1.3)

the other question, why CHAR when we already have SUBSTR

well ... one difference is that with SUBSTR, the default length of the result is the length of the variable used
regardless of how many characters are extracted while with CHAR, the length of the result is always 1

another is what happens in the LOG if the start location specified is incorrect ...


data x;
name = 'HUANG';
f_char = char(name,1);
f_substr = substr(name,1);

mistake0_char = char(name,0);
mistake0_substr = substr(name,0);

mistake10_char = char(name,10);
mistake10_substr = substr(name,10);
run;

proc contents data=x;
run;

the LOG ... no messages with CHAR ...

899 data x;
900 name = 'HUANG';
901 f_char = char(name,1);
902 f_substr = substr(name,1);
903
904 mistake0_char = char(name,0);
905 mistake0_substr = substr(name,0);
906
907 mistake10_char = char(name,10);
908 mistake10_substr = substr(name,10);
909 run;

NOTE: Invalid second argument to function SUBSTR at line 905 column 19.
NOTE: Invalid second argument to function SUBSTR at line 908 column 20.
name=HUANG f_char=H f_substr=HUANG mistake0_char= mistake0_substr= mistake10_char= mistake10_substr= _ERROR_=1 _N_=1
NOTE: The data set WORK.X has 1 observations and 7 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds


the OUTPUT ...

# Variable Type Len
2 f_char Char 1
3 f_substr Char 5
4 mistake0_char Char 1
5 mistake0_substr Char 5
6 mistake10_char Char 1
7 mistake10_substr Char 5
1 name Char 5






--
Mike Zdeb
U(a)Albany School of Public Health
One University Place
Rensselaer, New York 12144-3456
P/518-402-6479 F/630-604-1475

> Nice!!
>
> I've never noticed the use of Char() function. Is this from v9?
>
> Thanks.
>
> Ya
>
> On Fri, 26 Feb 2010 14:41:38 -0500, Mike Zdeb <msz03(a)ALBANY.EDU> wrote:
>
>>hi ... another idea ...
>>
>>data x;
>>iphx='99aa2233'x;
>>ip = catx('.',rank(char(iphx,1)),rank(char(iphx,2)),rank(char(iphx,3)),rank
> (char(iphx,4)));
>>put 'IP: ' ip;
>>run;
>>
>>IP: 153.170.34.51
>>
>>
>>
>>
>>--
>>Mike Zdeb
>>U(a)Albany School of Public Health
>>One University Place
>>Rensselaer, New York 12144-3456
>>P/518-402-6479 F/630-604-1475
>>
>>> Then use $hex. format to convert it first:
>>>
>>> 151 data _null_;
>>> 152 iphx='99aa2233'x;
>>> 153 iphxc=put(iphx,$hex.);
>>> 154 ipdec1=put(input(substr(iphxc,1,2),hex.),best.);
>>> 155 ipdec2=put(input(substr(iphxc,3,2),hex.),best.);
>>> 156 ipdec3=put(input(substr(iphxc,5,2),hex.),best.);
>>> 157 ipdec4=put(input(substr(iphxc,7,2),hex.),best.);
>>> 158 ipdec=compress(ipdec1||'.'||ipdec2||'.'||ipdec3||'.'||ipdec4);
>>> 159 put ipdec;
>>> 160 run;
>>>
>>> 153.170.34.51
>>>
>>>
>>> On Fri, 26 Feb 2010 13:34:42 -0500, Jack Kelly
>>> <John_J_Kelly(a)AO.USCOURTS.GOV> wrote:
>>>
>>>><snip>
>>>>Yes, use scan,input,put can do it:
>>>>
>>>>1 data _null_;
>>>>2 iphx='0xC0.0x00.0x02.0xEB';
>>>>3 ipdec1=put(input(scan(scan(iphx,1,'.'),2,'x'),hex.),best.);
>>>></snip>
>>>>
>>>>My mistake and thanks for the reply. I should have stated that the number
>>>>is hex with no dots, e.g. x'99aa2233'. It is an IBM format that they use
>>>>in most of their accounting type data. So I can't see how I can SCAN and
>>>>SUBSTR[N] only seems to work well with characters.
>>>
>
CONFIDENTIALITY NOTICE: This electronic message contains
information which may be legally confidential and or privileged and
does not in any case represent a firm ENERGY COMMODITY bid or offer
relating thereto which binds the sender without an additional
express written confirmation to that effect. The information is
intended solely for the individual or entity named above and access
by anyone else is unauthorized. If you are not the intended
recipient, any disclosure, copying, distribution, or use of the
contents of this information is prohibited and may be unlawful. If
you have received this electronic transmission in error, please
reply immediately to the sender that you have received the message
in error, and delete it. Thank you.