DATA Step, Macro, Functions and more

How to convert character value to binary value and assign to another binary value using data step?

Reply
Contributor
Posts: 22

How to convert character value to binary value and assign to another binary value using data step?


My_table has two fields, one is defined as [c_array] char(20), with values like ‘123456781ABCD234’. Another field is defined as [b_array] binary(8). The task is to convert value of c_array into binary and assign it to b_array.

 

thanks

 

Trusted Advisor
Posts: 1,131

Re: How to convert character value to binary value and assign to another binary value using data s

I found a similar thread in sas commnities, hope this answers your query

 

https://communities.sas.com/t5/General-SAS-Programming/Convert-character-variable-into-numeric-binar...

 

Thanks,
Jag
Respected Advisor
Posts: 4,654

Re: How to convert character value to binary value and assign to another binary value using data s

Beware of truncation. 20 hexadecimal numbers will require at least 80 bits of binary storage.

PG
Respected Advisor
Posts: 3,124

Re: How to convert character value to binary value and assign to another binary value using data s

 Are you doing a hex to binary conversion like @PGStats suggested, or a char to binary conversion? If hex-binary, given the length is 20, you may need to read it in as hex one digit at a time, and spit it out as binary, then concatenate them together to the length of 80.  If char-binary, there is a format $binaryw. you may need to use.

 

Take a look at format/informat $binaryw and binaryw.

Ask a Question
Discussion stats
  • 3 replies
  • 575 views
  • 0 likes
  • 4 in conversation