<?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 Find and Replace string in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Find-and-Replace-string/m-p/505273#M1125</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the below&amp;nbsp;code working:&lt;/P&gt;&lt;P&gt;I need help with &lt;STRONG&gt;looping the below code&lt;/STRONG&gt; such that the loop works for &lt;STRONG&gt;length(name)&lt;/STRONG&gt; number of times&amp;nbsp;and new_name is completely replaced except for the first string.&lt;/P&gt;&lt;P&gt;I want all the _1 and _2... concatenated to produce a variable named new_name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let string1=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ;
%let string2=`~!@#$%^&amp;amp;*()-=_+[]\{}|:,./&amp;lt;&amp;gt;?†°¬ŒÏ¾&amp;#127;ABCDEFGHIJKLMNOPQRSTUVWXYZ;
%put string1=&amp;amp;string1.;
%put string2=&amp;amp;string2.;

data encrypt;
set sashelp.class;
length new_name $25.;
new_name=name;
len=length(name);

new_name_1=substr(new_name,1,1);
new_name_2=substr(new_name,2,1);
index_1=index("&amp;amp;string1.",trim(new_name_1) );
index_2=index("&amp;amp;string1.",trim(new_name_2) );
_1=substr("&amp;amp;string2.",index_1,1);
_2=substr("&amp;amp;string2.",index_2,1);

drop new_name_1 new_name_2 index_1 index_2 len;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 17 Oct 2018 18:29:25 GMT</pubDate>
    <dc:creator>david27</dc:creator>
    <dc:date>2018-10-17T18:29:25Z</dc:date>
    <item>
      <title>Find and Replace string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Find-and-Replace-string/m-p/505273#M1125</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the below&amp;nbsp;code working:&lt;/P&gt;&lt;P&gt;I need help with &lt;STRONG&gt;looping the below code&lt;/STRONG&gt; such that the loop works for &lt;STRONG&gt;length(name)&lt;/STRONG&gt; number of times&amp;nbsp;and new_name is completely replaced except for the first string.&lt;/P&gt;&lt;P&gt;I want all the _1 and _2... concatenated to produce a variable named new_name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let string1=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ;
%let string2=`~!@#$%^&amp;amp;*()-=_+[]\{}|:,./&amp;lt;&amp;gt;?†°¬ŒÏ¾&amp;#127;ABCDEFGHIJKLMNOPQRSTUVWXYZ;
%put string1=&amp;amp;string1.;
%put string2=&amp;amp;string2.;

data encrypt;
set sashelp.class;
length new_name $25.;
new_name=name;
len=length(name);

new_name_1=substr(new_name,1,1);
new_name_2=substr(new_name,2,1);
index_1=index("&amp;amp;string1.",trim(new_name_1) );
index_2=index("&amp;amp;string1.",trim(new_name_2) );
_1=substr("&amp;amp;string2.",index_1,1);
_2=substr("&amp;amp;string2.",index_2,1);

drop new_name_1 new_name_2 index_1 index_2 len;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Oct 2018 18:29:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Find-and-Replace-string/m-p/505273#M1125</guid>
      <dc:creator>david27</dc:creator>
      <dc:date>2018-10-17T18:29:25Z</dc:date>
    </item>
    <item>
      <title>Re: Find and Replace string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Find-and-Replace-string/m-p/505289#M1126</link>
      <description>&lt;P&gt;I think you may be looking for function TRANSLATE which will replace characters from one list with those of another.&lt;/P&gt;
&lt;P&gt;You do realize that your two STRING variables are of different lengths though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data encrypt;
set sashelp.class;
length new_name $25.;
new_name=name;

new_name_1=translate(name,"&amp;amp;string2.","&amp;amp;string1");

run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Oct 2018 19:04:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Find-and-Replace-string/m-p/505289#M1126</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-17T19:04:20Z</dc:date>
    </item>
    <item>
      <title>Re: Find and Replace string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Find-and-Replace-string/m-p/505321#M1137</link>
      <description>&lt;P&gt;Thank You&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&lt;/P&gt;&lt;P&gt;Yes this is simple. But then translate would work only for character variables. correct?&lt;/P&gt;&lt;P&gt;I want help with building something that would also encrypt numeric variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Oct 2018 20:09:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Find-and-Replace-string/m-p/505321#M1137</guid>
      <dc:creator>david27</dc:creator>
      <dc:date>2018-10-17T20:09:24Z</dc:date>
    </item>
    <item>
      <title>Re: Find and Replace string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Find-and-Replace-string/m-p/505376#M1150</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215179"&gt;@david27&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank You&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Yes this is simple. But then translate would work only for character variables. correct?&lt;/P&gt;
&lt;P&gt;I want help with building something that would also encrypt numeric variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;To tell you the truth I couldn't actually follow the logic you were using in a short period of time. And any approach at all close will not "encrypt numeric" values because once you do something like this they are character anyway. So using PUT with your numeric value to create character value and then translate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;charactervalue = translate (put(numericvar,f8.2),"&amp;amp;string2.","&amp;amp;string1");&lt;/P&gt;
&lt;P&gt;The decrypt would be to do the reverse translate and use&amp;nbsp;input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Oct 2018 22:08:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Find-and-Replace-string/m-p/505376#M1150</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-17T22:08:34Z</dc:date>
    </item>
  </channel>
</rss>

