<?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: encryption of primary key using replace function - how about white spaces? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/encryption-of-primary-key-using-replace-function-how-about-white/m-p/226831#M40851</link>
    <description>&lt;P&gt;I do not think the "do" loop is necessary. I have changed your example slightly to replace " " with "_" which will avoid the leading space and trailing space problem.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA test;
  format e_STATSLINKAGE $8.;
  STATSLINKAGE="ABCDE FG";

  if index(STATSLINKAGE, "_") &amp;gt; 0 then do; 
    put "ERROR: sorry ... bad replacement character found in input data";
    abort;
  end; 

  /* change space to underscore */
  e_STATSLINKAGE=translate(STATSLINKAGE,
                          'HIJKLMNOPQRSTUVWXYZABCDEFG4567890123_',
                          'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ');
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There is another way. If you do not have a need to ever decrypt" the data back to its original value, you could&amp;nbsp;do&amp;nbsp;an MD5 hash.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA test2;
  fake_ssn = "000000000"; output;
  fake_ssn = "111111111"; output;
  fake_ssn = "999999999"; output;
RUN;

/* note that if you change your primary key to an MD5, it is a one-way 
   hash, and there is no way to decrypt it and convert it back to its 
   original value */
DATA test2_hashed;
  SET test2;
  length ssn_hashed $40;
  ssn_hashed = put(md5(fake_ssn),$hex32.);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 23 Sep 2015 00:58:41 GMT</pubDate>
    <dc:creator>hbi</dc:creator>
    <dc:date>2015-09-23T00:58:41Z</dc:date>
    <item>
      <title>encryption of primary key using replace function - how about white spaces?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/encryption-of-primary-key-using-replace-function-how-about-white/m-p/226827#M40849</link>
      <description>&lt;P&gt;Hi all.&lt;/P&gt;&lt;P&gt;So i got to know how to mask string-values primary keys using replace function as below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;format e_STATSLINKAGE $8.;&lt;BR /&gt;STATSLINKAGE="ABCDE FG";&lt;BR /&gt;do i = 1 to length(STATSLINKAGE);&lt;BR /&gt;e_STATSLINKAGE=e_STATSLINKAGE||translate(substr(STATSLINKAGE,i,1),'HIJKLMNOPQRSTUVWXYZABCDEFG4567890123 ','ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ');&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works really well...but until I came across a white space showing up inside these keys.&lt;/P&gt;&lt;P&gt;At the moment, the code strips any leading or trailing blanks as it genereates the encrpyted variable thus the white space gets stripped.&amp;nbsp;But I want to keep the white space as it is.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How would you achieve this without expanding the current code too much?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS experts, please advise&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2015 00:02:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/encryption-of-primary-key-using-replace-function-how-about-white/m-p/226827#M40849</guid>
      <dc:creator>willy06251</dc:creator>
      <dc:date>2015-09-23T00:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: encryption of primary key using replace function - how about white spaces?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/encryption-of-primary-key-using-replace-function-how-about-white/m-p/226830#M40850</link>
      <description>&lt;P&gt;You could use SUBSTR to overwrite one character at a time:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test;&lt;BR /&gt;format e_STATSLINKAGE $8.;&lt;BR /&gt;STATSLINKAGE="ABCDE FG";&lt;BR /&gt;do i = 1 to length(STATSLINKAGE);&lt;BR /&gt;&lt;STRONG&gt;substr(e_STATSLINKAGE,i,1)&lt;/STRONG&gt;=translate(substr(STATSLINKAGE,i,1),&lt;BR /&gt;'HIJKLMNOPQRSTUVWXYZABCDEFG4567890123 ',&lt;BR /&gt;'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ');&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2015 00:40:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/encryption-of-primary-key-using-replace-function-how-about-white/m-p/226830#M40850</guid>
      <dc:creator>dkb</dc:creator>
      <dc:date>2015-09-23T00:40:12Z</dc:date>
    </item>
    <item>
      <title>Re: encryption of primary key using replace function - how about white spaces?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/encryption-of-primary-key-using-replace-function-how-about-white/m-p/226831#M40851</link>
      <description>&lt;P&gt;I do not think the "do" loop is necessary. I have changed your example slightly to replace " " with "_" which will avoid the leading space and trailing space problem.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA test;
  format e_STATSLINKAGE $8.;
  STATSLINKAGE="ABCDE FG";

  if index(STATSLINKAGE, "_") &amp;gt; 0 then do; 
    put "ERROR: sorry ... bad replacement character found in input data";
    abort;
  end; 

  /* change space to underscore */
  e_STATSLINKAGE=translate(STATSLINKAGE,
                          'HIJKLMNOPQRSTUVWXYZABCDEFG4567890123_',
                          'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ');
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There is another way. If you do not have a need to ever decrypt" the data back to its original value, you could&amp;nbsp;do&amp;nbsp;an MD5 hash.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA test2;
  fake_ssn = "000000000"; output;
  fake_ssn = "111111111"; output;
  fake_ssn = "999999999"; output;
RUN;

/* note that if you change your primary key to an MD5, it is a one-way 
   hash, and there is no way to decrypt it and convert it back to its 
   original value */
DATA test2_hashed;
  SET test2;
  length ssn_hashed $40;
  ssn_hashed = put(md5(fake_ssn),$hex32.);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2015 00:58:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/encryption-of-primary-key-using-replace-function-how-about-white/m-p/226831#M40851</guid>
      <dc:creator>hbi</dc:creator>
      <dc:date>2015-09-23T00:58:41Z</dc:date>
    </item>
    <item>
      <title>Re: encryption of primary key using replace function - how about white spaces?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/encryption-of-primary-key-using-replace-function-how-about-white/m-p/226991#M40874</link>
      <description>Character substitution is incredibly easy to break, so don't use this for a public space.</description>
      <pubDate>Wed, 23 Sep 2015 20:23:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/encryption-of-primary-key-using-replace-function-how-about-white/m-p/226991#M40874</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2015-09-23T20:23:17Z</dc:date>
    </item>
  </channel>
</rss>

