<?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: Creating numeric composite key in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-numeric-composite-key/m-p/827621#M326928</link>
    <description>&lt;P&gt;The MD5() function returns 128 bits.&amp;nbsp; So at 8 bits per byte that is 16 bytes.&amp;nbsp; That is waaaaaay too many to convert into a single number.&amp;nbsp; So leave it as character and use the $HEX32 format to display it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  attrib pk_char length=$200;
  attrib pk length=$16 format=$hex32.;
  pk_char = catx('_',of CUSTOMER_ID CUSTOMER_SYSTEM_ID PRODUCT_ID COVERAGE_ID OBJECT_ID);
  pk = md5(pk_char);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also there is no need to attach the $200 format to PK_CHAR. SAS does not need any special instructions for how to display display character strings.&lt;/P&gt;</description>
    <pubDate>Mon, 08 Aug 2022 14:25:40 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-08-08T14:25:40Z</dc:date>
    <item>
      <title>Creating numeric composite key</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-numeric-composite-key/m-p/827579#M326918</link>
      <description>&lt;P&gt;We've got several large tables where the primary key consists of multiple char variables. These are used in multiple heavy joins. My example table uses these 5 chars as PK: CUSTOMER_ID, CUSTOMER_SYSTEM_ID, PRODUCT_ID, COVERAGE_ID, OBJECT_ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to create 1 numeric composite key instead. Primarily to make the joins run faster. But also because our reusable script (used to process multiple tables) can be simplified by always having 1 PK per table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My plan is to append the char variables together, and then use MD5 &amp;amp; HEX to create the numeric composite key value. Like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	attrib pk_char format=$200.;
	attrib pk_nr format=20.0;
	pk_char = CUSTOMER_ID || '_' || CUSTOMER_SYSTEM_ID || '_' || PRODUCT_ID || '_' || COVERAGE_ID || '_' || OBJECT_ID;
	pk_nr = input(put(md5(pk_char),$hex13.),hex13.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;1) Is this a sensible approach, or do you have better suggestions?&lt;/P&gt;
&lt;P&gt;2) I'm satisfied with format=$200 for the concatinated character string. This value should never be exceeded for any of the tables. An example value it might get today (from the example table) is "123684525218_562448_V48_26457_3". But I'm clueless about what hex format to go for. Would hex13 be fine for creating a uniqe numerical value for a string consisting of up to 200 symbols?&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2022 11:37:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-numeric-composite-key/m-p/827579#M326918</guid>
      <dc:creator>EinarRoed</dc:creator>
      <dc:date>2022-08-08T11:37:18Z</dc:date>
    </item>
    <item>
      <title>Re: Creating numeric composite key</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-numeric-composite-key/m-p/827621#M326928</link>
      <description>&lt;P&gt;The MD5() function returns 128 bits.&amp;nbsp; So at 8 bits per byte that is 16 bytes.&amp;nbsp; That is waaaaaay too many to convert into a single number.&amp;nbsp; So leave it as character and use the $HEX32 format to display it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  attrib pk_char length=$200;
  attrib pk length=$16 format=$hex32.;
  pk_char = catx('_',of CUSTOMER_ID CUSTOMER_SYSTEM_ID PRODUCT_ID COVERAGE_ID OBJECT_ID);
  pk = md5(pk_char);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also there is no need to attach the $200 format to PK_CHAR. SAS does not need any special instructions for how to display display character strings.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2022 14:25:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-numeric-composite-key/m-p/827621#M326928</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-08T14:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: Creating numeric composite key</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-numeric-composite-key/m-p/828026#M327082</link>
      <description>Very useful, I will go for your suggestion. Thanks!</description>
      <pubDate>Wed, 10 Aug 2022 06:03:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-numeric-composite-key/m-p/828026#M327082</guid>
      <dc:creator>EinarRoed</dc:creator>
      <dc:date>2022-08-10T06:03:42Z</dc:date>
    </item>
  </channel>
</rss>

