<?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 encrypt group ID with values from a dataset in SAS Health and Life Sciences</title>
    <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/How-to-encrypt-group-ID-with-values-from-a-dataset/m-p/9829#M842</link>
    <description>Thanks Reeza!&lt;BR /&gt;
This makes a lot of sense. In fact, I'd tried something similar though not same, trying to use put function for using user defined format. However, it is the part where I need to concatenate all substrings together that is throwing me off. Coz even if I use lag function to retain the last value of j or new_j, it will still give value for only last 2 characters, and not a combined string of all previous characters.&lt;BR /&gt;
&lt;BR /&gt;
Any suggestions on that one, please?&lt;BR /&gt;
&lt;BR /&gt;
Thanks again.</description>
    <pubDate>Wed, 08 Jun 2011 23:48:17 GMT</pubDate>
    <dc:creator>SAScert</dc:creator>
    <dc:date>2011-06-08T23:48:17Z</dc:date>
    <item>
      <title>How to encrypt group ID with values from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/How-to-encrypt-group-ID-with-values-from-a-dataset/m-p/9827#M840</link>
      <description>Hi,&lt;BR /&gt;
I have a task of encrypting group IDs using random values - either alphabet or number. I've created a format to map each of the 26 alphabets to a two digit random number, and each single digit number (0-9) to a two digit alpha-numeric random value, such that none of the values appear more than once.&lt;BR /&gt;
Now, the question is, how do I change the 9 digits of group ID to 18 encrypted digits based on the format values?&lt;BR /&gt;
&lt;BR /&gt;
e.g. proc format ;&lt;BR /&gt;
value $xwalk&lt;BR /&gt;
'A' = '10'&lt;BR /&gt;
'B' = '19'&lt;BR /&gt;
'C' = '26'&lt;BR /&gt;
'D' = '18'&lt;BR /&gt;
'E' = '35'&lt;BR /&gt;
'1' = 'A0'&lt;BR /&gt;
'2' = 'B3'&lt;BR /&gt;
'3' = 'E8'&lt;BR /&gt;
'4' = 'Q9'&lt;BR /&gt;
'5' = 'I2'&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
In this case, if my group ID is 'AD245', it should become '1018B3Q9I2' after encryption.&lt;BR /&gt;
&lt;BR /&gt;
I've tried using tranwrd function with do loop, but that doesn't allow me to read crosswalk values from a dataset or format.&lt;BR /&gt;
&lt;BR /&gt;
Please suggest what code I can use to get there.&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
      <pubDate>Wed, 08 Jun 2011 22:29:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/How-to-encrypt-group-ID-with-values-from-a-dataset/m-p/9827#M840</guid>
      <dc:creator>SAScert</dc:creator>
      <dc:date>2011-06-08T22:29:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to encrypt group ID with values from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/How-to-encrypt-group-ID-with-values-from-a-dataset/m-p/9828#M841</link>
      <description>Look at the put function...&lt;BR /&gt;
You need to build in the loop and the code to concatenate the strings together rather than output like I did, but hopefully you get the idea. &lt;BR /&gt;
&lt;BR /&gt;
You can create a proc format from a dataset with cntlin option if you need to.&lt;BR /&gt;
&lt;BR /&gt;
HTH,&lt;BR /&gt;
Reeza&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
ie. &lt;BR /&gt;
data want;&lt;BR /&gt;
	groupid='AD245';&lt;BR /&gt;
&lt;BR /&gt;
	length new_j $2. ;&lt;BR /&gt;
	do i=1 to 5;&lt;BR /&gt;
		j=substr(groupid, i,1);&lt;BR /&gt;
		new_j=compress(put(j, $xwalk.));&lt;BR /&gt;
		output;&lt;BR /&gt;
		&lt;BR /&gt;
	end;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 08 Jun 2011 22:56:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/How-to-encrypt-group-ID-with-values-from-a-dataset/m-p/9828#M841</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2011-06-08T22:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to encrypt group ID with values from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/How-to-encrypt-group-ID-with-values-from-a-dataset/m-p/9829#M842</link>
      <description>Thanks Reeza!&lt;BR /&gt;
This makes a lot of sense. In fact, I'd tried something similar though not same, trying to use put function for using user defined format. However, it is the part where I need to concatenate all substrings together that is throwing me off. Coz even if I use lag function to retain the last value of j or new_j, it will still give value for only last 2 characters, and not a combined string of all previous characters.&lt;BR /&gt;
&lt;BR /&gt;
Any suggestions on that one, please?&lt;BR /&gt;
&lt;BR /&gt;
Thanks again.</description>
      <pubDate>Wed, 08 Jun 2011 23:48:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/How-to-encrypt-group-ID-with-values-from-a-dataset/m-p/9829#M842</guid>
      <dc:creator>SAScert</dc:creator>
      <dc:date>2011-06-08T23:48:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to encrypt group ID with values from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/How-to-encrypt-group-ID-with-values-from-a-dataset/m-p/9830#M843</link>
      <description>Suggest sharing your SAS code that is not working.  Also, you likely need to look at using both a LENGTH and a RETAIN statement -- mostly the RETAIN is needed if your DATA step iterates (bottom back to the top) instead of having a DO/END loop with a SET / INPUT statement code-paragraph for data manipulation.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Suggested Google advanced search argument, this topic / post:&lt;BR /&gt;
&lt;BR /&gt;
data step retain statement site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
retain statement documentation site:sas.com</description>
      <pubDate>Thu, 09 Jun 2011 10:19:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/How-to-encrypt-group-ID-with-values-from-a-dataset/m-p/9830#M843</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-06-09T10:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to encrypt group ID with values from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/How-to-encrypt-group-ID-with-values-from-a-dataset/m-p/9831#M844</link>
      <description>If your ID's are always the same length, ie 9 as in your description the following works. If not then you'll need a different solution, using retain and length statement,where you basically append the new read value onto the string after encoding it. &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data want;&lt;BR /&gt;
groupid='AD245CD32';&lt;BR /&gt;
&lt;BR /&gt;
length code: $2. j: $1.;&lt;BR /&gt;
&lt;BR /&gt;
array code(9) $ code1-code9;&lt;BR /&gt;
array temp(9) $ j1-j9;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
do i=1 to 9;&lt;BR /&gt;
	temp&lt;I&gt;=substr(groupid, i, 1);&lt;BR /&gt;
	code&lt;I&gt;=put(temp&lt;I&gt;, $xwalk.);&lt;BR /&gt;
	&lt;BR /&gt;
&lt;BR /&gt;
end;&lt;BR /&gt;
new_code=cats(of code1-code9);&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;</description>
      <pubDate>Thu, 09 Jun 2011 16:15:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/How-to-encrypt-group-ID-with-values-from-a-dataset/m-p/9831#M844</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2011-06-09T16:15:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to encrypt group ID with values from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/How-to-encrypt-group-ID-with-values-from-a-dataset/m-p/9832#M845</link>
      <description>Yes, my IDs are always of the same length, and this solution worked! Thanks so much for your help!&lt;BR /&gt;
&lt;BR /&gt;
I used the following code, only thing different was, instead of cats function, I used concatenation with array values within the do loop - &lt;BR /&gt;
&lt;BR /&gt;
data want;&lt;BR /&gt;
groupid='AD245CD32';&lt;BR /&gt;
&lt;BR /&gt;
length code: $2. j: $1. new_code $9.;&lt;BR /&gt;
retain new_code '';&lt;BR /&gt;
&lt;BR /&gt;
array code(9) $ code1-code9;&lt;BR /&gt;
array temp(9) $ j1-j9;&lt;BR /&gt;
&lt;BR /&gt;
do i=1 to 9;&lt;BR /&gt;
temp(i)=substr(groupid, i, 1);&lt;BR /&gt;
code(i)=put(temp(i), $xwalk.);&lt;BR /&gt;
&lt;BR /&gt;
new_code=compress(new_code || code(i));&lt;BR /&gt;
&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
run;</description>
      <pubDate>Thu, 09 Jun 2011 17:35:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/How-to-encrypt-group-ID-with-values-from-a-dataset/m-p/9832#M845</guid>
      <dc:creator>SAScert</dc:creator>
      <dc:date>2011-06-09T17:35:49Z</dc:date>
    </item>
  </channel>
</rss>

