<?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: Problem converting HEX format to character in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-converting-HEX-format-to-character/m-p/541975#M149746</link>
    <description>&lt;P&gt;Unfortunately I didn't create the data sets, and the guy who did no longer works here.&amp;nbsp; However, he left his code as documentation.&amp;nbsp; The data were pulled from a restricted-access data warehouse, not from Excel.&amp;nbsp; Here is the section where the encrypted_ID is created for the PREVIOUS data sets:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	/*  1.4 Encrypt beneficiary_id */
	proc sql;

	    create table work.scd_data_3 as

	    select  sha256(put(input(beneficiary_id, 10.), z10.))         as encrypted_id format $hex64.
				,category
				,category_description
	    from    work.scd_data_2;

	quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And this is how he created it for the CURRENT data set:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* 5.2 Create an encrypted ID */
proc sql;

create table work.encrypted_ids_2 as

select beneficiary_id
,sha256(beneficiary_id) as encrypted_id format $hex64.
from work.encrypted_ids_1;

quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 11 Mar 2019 12:15:24 GMT</pubDate>
    <dc:creator>Wolverine</dc:creator>
    <dc:date>2019-03-11T12:15:24Z</dc:date>
    <item>
      <title>Problem converting HEX format to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-converting-HEX-format-to-character/m-p/541077#M149351</link>
      <description>&lt;P&gt;I have a collection of data that with IDs that have been encrypted in a hex format.&amp;nbsp; Sometimes, as part of testing, I find it helpful to follow just a few cases thru the syntax to make the correct cases are being selected at each step.&amp;nbsp; To do so, I use the following syntax in a data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;encrypted_id2 = put(encrypted_id, $hex64.);&lt;BR /&gt;IF encrypted_ID2 ^in ("0720275C8B0B0C376C1B272DA78FD0DF10FB5408EDE76CD21C637EF2F42FC4AB") then delete;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've used this bit of syntax dozens of times while working with this data.&amp;nbsp; But on this particular occasion, I got an error that I am at a loss to explain:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;ERROR 29-185: Width specified for format HEX is invalid.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've confirmed that the ID is in fact 64 characters.&amp;nbsp; I tried searching online but couldn't find any useful info.&amp;nbsp; So what could possibly cause this issue?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2019 13:42:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-converting-HEX-format-to-character/m-p/541077#M149351</guid>
      <dc:creator>Wolverine</dc:creator>
      <dc:date>2019-03-07T13:42:35Z</dc:date>
    </item>
    <item>
      <title>Re: Problem converting HEX format to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-converting-HEX-format-to-character/m-p/541079#M149353</link>
      <description>&lt;P&gt;Most likely your id variable is numeric instead of character.&lt;/P&gt;
&lt;PRE&gt;9     data _null_;
10      length x 8;
11
12      y =put(x,$hex64.);
                 -------
                 29
WARNING: Variable x has already been defined as numeric.
ERROR 29-185: Width specified for format HEX is invalid.

13    run;
&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Mar 2019 13:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-converting-HEX-format-to-character/m-p/541079#M149353</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-07T13:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: Problem converting HEX format to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-converting-HEX-format-to-character/m-p/541081#M149355</link>
      <description>&lt;P&gt;Maxim 3: Know Your Data.&lt;/P&gt;
&lt;P&gt;encrypted_id is numeric, so SAS (trying to be helpful) changes the character format $HEX to the numeric format HEX (note the missing dollar sign in the "ERROR 29-185: Width specified for format HEX is invalid."). But since the numeric format expects a maximum of 8 bytes as input (the maximum number of bytes for SAS numbers), it only allows up to 16 as width (Maxim 1: Read the Documentation).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your put() function call to make sense, enrypted_id needs to be character with a length of 32.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2019 13:56:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-converting-HEX-format-to-character/m-p/541081#M149355</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-07T13:56:45Z</dc:date>
    </item>
    <item>
      <title>Re: Problem converting HEX format to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-converting-HEX-format-to-character/m-p/541145#M149372</link>
      <description>&lt;P&gt;You're right -- I got the same warning just above the error: WARNING: Variable encrypted_id has already been defined as numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That means that this particular data file was created differently than the rest of the files in this data collection.&amp;nbsp; I ran proc contents on this file, and on another file from this collection.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Current file: encrypted_id Num 8&lt;/P&gt;
&lt;P&gt;Other file: encrypted_id Char 200 $HEX64.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't understand how encrypted_id can be 8-digit numeric when it includes letters and has an actual length of 64.&amp;nbsp; The long string of numbers and letters in my first bit of syntax was copied directly from the SAS data file and is indeed 64 characters long.&amp;nbsp; And how do I delete any record that doesn't belong to a specific ID?&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2019 16:26:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-converting-HEX-format-to-character/m-p/541145#M149372</guid>
      <dc:creator>Wolverine</dc:creator>
      <dc:date>2019-03-07T16:26:27Z</dc:date>
    </item>
    <item>
      <title>Re: Problem converting HEX format to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-converting-HEX-format-to-character/m-p/541891#M149711</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/43822"&gt;@Wolverine&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;You're right -- I got the same warning just above the error: WARNING: Variable encrypted_id has already been defined as numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That means that this particular data file was created differently than the rest of the files in this data collection.&amp;nbsp; I ran proc contents on this file, and on another file from this collection.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Current file: encrypted_id Num 8&lt;/P&gt;
&lt;P&gt;Other file: encrypted_id Char 200 $HEX64.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't understand how encrypted_id can be 8-digit numeric when it includes letters and has an actual length of 64.&amp;nbsp; The long string of numbers and letters in my first bit of syntax was copied directly from the SAS data file and is indeed 64 characters long.&amp;nbsp; And how do I delete any record that doesn't belong to a specific ID?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You need to go back in your process and look how the dataset was created.&lt;/P&gt;
&lt;P&gt;If you have proc import and/or the processing of Excel files somewhere in your process, you need to replace that with a reliable method. Importing Excel files is not reliable and therefore useless for repeated processing.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 06:35:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-converting-HEX-format-to-character/m-p/541891#M149711</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-11T06:35:06Z</dc:date>
    </item>
    <item>
      <title>Re: Problem converting HEX format to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-converting-HEX-format-to-character/m-p/541975#M149746</link>
      <description>&lt;P&gt;Unfortunately I didn't create the data sets, and the guy who did no longer works here.&amp;nbsp; However, he left his code as documentation.&amp;nbsp; The data were pulled from a restricted-access data warehouse, not from Excel.&amp;nbsp; Here is the section where the encrypted_ID is created for the PREVIOUS data sets:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	/*  1.4 Encrypt beneficiary_id */
	proc sql;

	    create table work.scd_data_3 as

	    select  sha256(put(input(beneficiary_id, 10.), z10.))         as encrypted_id format $hex64.
				,category
				,category_description
	    from    work.scd_data_2;

	quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And this is how he created it for the CURRENT data set:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* 5.2 Create an encrypted ID */
proc sql;

create table work.encrypted_ids_2 as

select beneficiary_id
,sha256(beneficiary_id) as encrypted_id format $hex64.
from work.encrypted_ids_1;

quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Mar 2019 12:15:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-converting-HEX-format-to-character/m-p/541975#M149746</guid>
      <dc:creator>Wolverine</dc:creator>
      <dc:date>2019-03-11T12:15:24Z</dc:date>
    </item>
    <item>
      <title>Re: Problem converting HEX format to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-converting-HEX-format-to-character/m-p/541989#M149749</link>
      <description>&lt;P&gt;Both uses of the sha256 function create a character variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input beneficiary_id :$10.;
cards;
0123456789
;
run;

proc sql;
create table want1 as
select
  beneficiary_id,
  sha256(put(input(beneficiary_id, 10.), z10.)) as encrypted_id1 format $hex64.,
  sha256(beneficiary_id) as encrypted_id2 format $hex64.
from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It's just that the second version allows non-numeric data in the input, but the input (beneficiary_id) has to be character for both versions to work.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 12:51:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-converting-HEX-format-to-character/m-p/541989#M149749</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-11T12:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: Problem converting HEX format to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-converting-HEX-format-to-character/m-p/542015#M149756</link>
      <description>&lt;P&gt;The data is restricted, and beneficiary_id can be linked to patient names.&amp;nbsp; So beneficiary_id&amp;nbsp; is converted to encrypted_ID, and then beneficiary_id is dropped from the dataset before I'm allowed to have access to it.&amp;nbsp; So, going back to the original question, how do I convert encrypted_id so I can I create a test dataset that only includes a few specific encrypted_id's?&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 13:48:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-converting-HEX-format-to-character/m-p/542015#M149756</guid>
      <dc:creator>Wolverine</dc:creator>
      <dc:date>2019-03-11T13:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: Problem converting HEX format to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-converting-HEX-format-to-character/m-p/542016#M149757</link>
      <description>&lt;P&gt;What I wanted to point at:&lt;/P&gt;
&lt;P&gt;BOTH codes create a character variable. Since your initial problem seems to be that you have a dataset where encrypted_id is numeric, this dataset CANNOT come from one of the codes you posted.&lt;/P&gt;
&lt;P&gt;It may even be that encrypted_id does not exist in this dataset, and is created by SAS on-the-fly, which would make it numeric (per default). In that case you would also most likely get an "uninitialized" NOTE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please post the log of the &lt;EM&gt;whole&lt;/EM&gt; step that results in the message&lt;/P&gt;
&lt;PRE&gt;ERROR 29-185: Width specified for format HEX is invalid.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 13:56:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-converting-HEX-format-to-character/m-p/542016#M149757</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-11T13:56:25Z</dc:date>
    </item>
  </channel>
</rss>

