<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to convert binary to hexadecimal in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-binary-to-hexadecimal/m-p/516796#M139618</link>
    <description>&lt;P&gt;Did you read the bit string using BINARY in-format?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;34   data _null_;
35      infile cards firstobs=2;
36      input b:binary. x:$hex2.;
37      put b=binary. b=hex2. b= x=$hex2.;
38      cards;

b=10001101 b=8D b=141 x=8D
b=10100001 b=A1 b=161 x=A1
b=10100000 b=A0 b=160 x=A0
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 28 Nov 2018 16:54:36 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2018-11-28T16:54:36Z</dc:date>
    <item>
      <title>How to convert binary to hexadecimal</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-binary-to-hexadecimal/m-p/516792#M139616</link>
      <description>&lt;P&gt;Hi, I have a data set that contains binary numbers and I want to convert them to hexadecimal values.&lt;/P&gt;&lt;P&gt;The format of binary variable is&amp;nbsp;&lt;SPAN&gt;binary8.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I have:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;binary&lt;/TD&gt;&lt;TD&gt;hexa&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10001101&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10100001&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10100000&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I want:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;binary&lt;/TD&gt;&lt;TD&gt;hexa&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10001101&lt;/TD&gt;&lt;TD&gt;8D&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10100001&lt;/TD&gt;&lt;TD&gt;A1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10100000&lt;/TD&gt;&lt;TD&gt;A0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I already tried with informat/format with hex./$hex. but it does not work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me with that?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 16:46:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-binary-to-hexadecimal/m-p/516792#M139616</guid>
      <dc:creator>dera</dc:creator>
      <dc:date>2018-11-28T16:46:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert binary to hexadecimal</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-binary-to-hexadecimal/m-p/516796#M139618</link>
      <description>&lt;P&gt;Did you read the bit string using BINARY in-format?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;34   data _null_;
35      infile cards firstobs=2;
36      input b:binary. x:$hex2.;
37      put b=binary. b=hex2. b= x=$hex2.;
38      cards;

b=10001101 b=8D b=141 x=8D
b=10100001 b=A1 b=161 x=A1
b=10100000 b=A0 b=160 x=A0
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Nov 2018 16:54:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-binary-to-hexadecimal/m-p/516796#M139618</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2018-11-28T16:54:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert binary to hexadecimal</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-binary-to-hexadecimal/m-p/516998#M139682</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/236159"&gt;@dera&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you know, Base SAS has only two variable types: numeric and character. Obviously, the former is the natural choice for your values. I take it that you have assigned the BINARY8. format permanently to variable BINARY in your existing dataset. This means that the values 141, 161, 160 stored in this variable are displayed as 10001101, etc. So, you could create a copy of variable BINARY, call it HEXA and assign&amp;nbsp;the HEX2. format to it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input binary binary.;
format binary binary8.;
cards;
10001101
10100001
10100000
;

data want;
set have;
hexa=binary;
format hexa hex2.;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;  binary    hexa

10001101     8D
10100001     A1
10100000     A0&lt;/PRE&gt;
&lt;P&gt;However, the question is: What is the purpose of a redundant copy of a variable? For reporting purposes it is not needed:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=have;
column binary=b binary=h; /* creates aliases B and H for BINARY */
define b / display;
define h / format=hex2. 'hexa' width=4;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;    binary  hexa
  10001101    8D
  10100001    A1
  10100000    A0&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Nov 2018 11:25:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-binary-to-hexadecimal/m-p/516998#M139682</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-11-29T11:25:31Z</dc:date>
    </item>
  </channel>
</rss>

