Help using Base SAS procedures

How to convert hexadecimal to character?

Accepted Solution Solved
Reply
Regular Contributor
Posts: 222
Accepted Solution

How to convert hexadecimal to character?


Hello everyone,

I have a data set  has a hexadecimal variable,I want to convert it  into character,please advise.(for example 6B should convert to k)

for your reference,the following website list the ralationship of hex and character.

http://www.asciitable.com/

Thanks

Mike.

data have;

input hex $;

cards;

4D

4F

76

20

28

6B

;

run;


Accepted Solutions
Solution
‎08-10-2012 03:53 PM
Valued Guide
Posts: 765

Re: How to convert hexadecimal to character?

Posted in reply to Mike_Davis

hi ...

data have;

input hex $;

cards;

4D

4F

76

20

28

6B

;

data want;

set have;

new = byte(input(hex,hex.));

run;

hex    new

4D      M

4F      O

76      v

20

28      (

6B      k

View solution in original post


All Replies
Regular Contributor
Posts: 222

Re: How to convert hexadecimal to character?

Posted in reply to Mike_Davis

here is my ugly method:

please advise

I hope there is a function could be use directly.

Thanks

data table;
      do ascii=0 to 255;
            char=byte(ascii);
            put ascii= char=;
            hex=put(char,$HEX.);
   output;
      end;
run;
data have;
input hex $;
cards;
4D
4F
76
23
20
28
24
47
6B
52
;
run;

proc sql noprint;
create table want as
select a.*,b.char
from have as a
left join table as b
on a.hex=b.hex
;
quit;

Solution
‎08-10-2012 03:53 PM
Valued Guide
Posts: 765

Re: How to convert hexadecimal to character?

Posted in reply to Mike_Davis

hi ...

data have;

input hex $;

cards;

4D

4F

76

20

28

6B

;

data want;

set have;

new = byte(input(hex,hex.));

run;

hex    new

4D      M

4F      O

76      v

20

28      (

6B      k

Regular Contributor
Posts: 222

Re: How to convert hexadecimal to character?

Thanks a lot Mike

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 9741 views
  • 3 likes
  • 2 in conversation