<?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: Checking first byte of HEX4 format? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Checking-first-byte-of-HEX4-format/m-p/130395#M35504</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sounds like you are talking about a number and not a character string. Otherwise SAS would have complained if you tried to use the numeric format HEX. instead of the character format $HEX.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You want to test the digit in a specific place then you could apply some arithmetic to the problem. For example to test the digit in the 100ths place :&lt;/P&gt;&lt;P&gt; if mod(int(x/100),10) = 6 then ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If instead you want to test the most significant digit irrespective of magnitude it might be easiest to convert it to a character string using put functions.&lt;/P&gt;&lt;P&gt;if left(put(x,10)) =: '6' then ...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 10 Jul 2013 14:36:05 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2013-07-10T14:36:05Z</dc:date>
    <item>
      <title>Checking first byte of HEX4 format?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Checking-first-byte-of-HEX4-format/m-p/130391#M35500</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I need to check the value of the first byte from a HEX4 format field.&lt;/P&gt;&lt;P&gt;The value of the first observation is: 6EA0.&lt;/P&gt;&lt;P&gt;I've tried assiging the field to a defined character field in a data step and checking the substr(*,1,1) and various other ways with no success.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Jul 2013 12:51:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Checking-first-byte-of-HEX4-format/m-p/130391#M35500</guid>
      <dc:creator>G_I_Jeff</dc:creator>
      <dc:date>2013-07-10T12:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: Checking first byte of HEX4 format?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Checking-first-byte-of-HEX4-format/m-p/130392#M35501</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is not clear to me where this data exists.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This example may be helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV style="font-family: Courier New; font-size: 11pt;"&gt;&lt;STRONG style="color: #008080; background-color: #ffffff;"&gt;17&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data _null_;&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG style="color: #008080; background-color: #ffffff;"&gt;18&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x=&lt;/SPAN&gt;&lt;SPAN style="color: #800080; background-color: #ffffff;"&gt;'6EA0'x&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG style="color: #008080; background-color: #ffffff;"&gt;19&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x1 = first(x);&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG style="color: #008080; background-color: #ffffff;"&gt;20&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put x1= x1=&lt;/SPAN&gt;&lt;SPAN style="color: #008080; background-color: #ffffff;"&gt;hex2.&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG style="color: #008080; background-color: #ffffff;"&gt;21&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;x1=n x1=6E&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Jul 2013 13:09:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Checking-first-byte-of-HEX4-format/m-p/130392#M35501</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2013-07-10T13:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: Checking first byte of HEX4 format?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Checking-first-byte-of-HEX4-format/m-p/130393#M35502</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data_null_;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the example. I can reference the first byte of the HEX field, but I need to check the first character. I know how to accomplish this in COBOL or Assembler, just don't know how to do it in SAS. Sorry, should have made myself a little clearer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to check the first character to see if it's a numeric 6 to assign another field a value:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF X1 =: '06'X THEN X2 = 'A';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not 100% clear on how SAS is storing this value. I see the format in the storing pdb is HEX4, but it seems SAS is treating the value as character (which is baffling me).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Jul 2013 13:28:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Checking-first-byte-of-HEX4-format/m-p/130393#M35502</guid>
      <dc:creator>G_I_Jeff</dc:creator>
      <dc:date>2013-07-10T13:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: Checking first byte of HEX4 format?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Checking-first-byte-of-HEX4-format/m-p/130394#M35503</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Jeff,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SAS lets you store hex strings as either character or numeric.&amp;nbsp; The way you refer to them depends on how they are stored.&amp;nbsp; Either of these is permissible:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hex_num = 6EA0x;&lt;/P&gt;&lt;P&gt;hex_char = '6EA0'x;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HEX_NUM would be stored in SAS's usual numeric format, so you could check it with:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if put(hex_num, hex4.) =: '06' then X2='A';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HEX_CHAR would be stored as the two-byte character equivalent of 6E A0, so you could check it with:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if put(hex_char, $hex4.) =: '06' then X2='A';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Jul 2013 13:52:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Checking-first-byte-of-HEX4-format/m-p/130394#M35503</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-07-10T13:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: Checking first byte of HEX4 format?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Checking-first-byte-of-HEX4-format/m-p/130395#M35504</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sounds like you are talking about a number and not a character string. Otherwise SAS would have complained if you tried to use the numeric format HEX. instead of the character format $HEX.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You want to test the digit in a specific place then you could apply some arithmetic to the problem. For example to test the digit in the 100ths place :&lt;/P&gt;&lt;P&gt; if mod(int(x/100),10) = 6 then ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If instead you want to test the most significant digit irrespective of magnitude it might be easiest to convert it to a character string using put functions.&lt;/P&gt;&lt;P&gt;if left(put(x,10)) =: '6' then ...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Jul 2013 14:36:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Checking-first-byte-of-HEX4-format/m-p/130395#M35504</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-07-10T14:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: Checking first byte of HEX4 format?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Checking-first-byte-of-HEX4-format/m-p/130396#M35505</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Astounding,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I totally agree with you and I believe that your numeric example should be working, but it doesn't.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is my exact code (latest I've tried). DEVNR is type=num len=5 format=HEX4:&lt;/P&gt;&lt;P&gt;IF PUT(DEVNR,HEX4.) = 06X THEN DEVTYPE='V';&lt;/P&gt;&lt;P&gt;ELSE DEVTYPE='P';&lt;/P&gt;&lt;P&gt;My education/training tells me that the actual DEVNR field should look like '06EA0F', a 3 byte length field. When I list the variable, it shows a 4 numeric ( I assume) length field in the listing. Is SAS maybe padding this field with zeros? Is it NOT storing it as a true HEX compressed field? Or am I totally way off base here?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Jul 2013 15:22:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Checking-first-byte-of-HEX4-format/m-p/130396#M35505</guid>
      <dc:creator>G_I_Jeff</dc:creator>
      <dc:date>2013-07-10T15:22:31Z</dc:date>
    </item>
    <item>
      <title>Re: Checking first byte of HEX4 format?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Checking-first-byte-of-HEX4-format/m-p/130397#M35506</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Jeff,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A couple of factors are at work here. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First, there is no special storage format in SAS for numeric hex values.&amp;nbsp; All numerics get stored in the same floating point format, and all can be expressed in hex format.&amp;nbsp; For example, you could try:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;value = 255;&lt;/P&gt;&lt;P&gt;put value hex2.;&lt;/P&gt;&lt;P&gt;put value hex3.;&lt;/P&gt;&lt;P&gt;put value hex4.;&lt;/P&gt;&lt;P&gt;Second, the PUT function always returns a character string.&amp;nbsp; It doesn't matter whether the first argument is character or numeric, the result is always an expression of a value in a format which means a character string.&amp;nbsp; You could try (and then run PROC PRINT / PROC CONTENTS):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;year=204;&lt;/P&gt;&lt;P&gt;result = put(year, z4.);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So if DEVNR is a numeric, how it was created doesn't really matter.&amp;nbsp; It gets stored in the same format internally no matter what.&amp;nbsp; If it was generated by reading in a character string from hex, you could test it this way:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*devnr = 06AAx;&lt;/P&gt;&lt;P&gt;if put(devnr, hex4.) =: '06' then devtype='V';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think I've answered your questions, but feel free to ask again if this needs more detail.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Jul 2013 15:42:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Checking-first-byte-of-HEX4-format/m-p/130397#M35506</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-07-10T15:42:11Z</dc:date>
    </item>
  </channel>
</rss>

