<?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 substr in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/substr/m-p/417327#M26862</link>
    <description>&lt;P&gt;&lt;EM&gt;I have a requirement where the String has to be masked with the letter 'x'.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;for. eg. Sreelekha should be 'xxxxxxxxx'.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;I used the substr function to do this:&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;For a certain, column in a table where the length of the string is quite long, the string is getting replaced with just&amp;nbsp;1 X. ( x).Please refer screenshot.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Can you please help me with this issue.&lt;/EM&gt;&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, 30 Nov 2017 07:45:57 GMT</pubDate>
    <dc:creator>Sreelekha</dc:creator>
    <dc:date>2017-11-30T07:45:57Z</dc:date>
    <item>
      <title>substr</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/substr/m-p/417327#M26862</link>
      <description>&lt;P&gt;&lt;EM&gt;I have a requirement where the String has to be masked with the letter 'x'.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;for. eg. Sreelekha should be 'xxxxxxxxx'.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;I used the substr function to do this:&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;For a certain, column in a table where the length of the string is quite long, the string is getting replaced with just&amp;nbsp;1 X. ( x).Please refer screenshot.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Can you please help me with this issue.&lt;/EM&gt;&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, 30 Nov 2017 07:45:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/substr/m-p/417327#M26862</guid>
      <dc:creator>Sreelekha</dc:creator>
      <dc:date>2017-11-30T07:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: substr</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/substr/m-p/417329#M26863</link>
      <description>&lt;P&gt;Post example data (in a datastep, see &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;) and your code. Follow the advice in&amp;nbsp;&lt;A href="https://communities.sas.com/t5/help/faqpage/faq-category-id/posting?nobounce" target="_blank"&gt;https://communities.sas.com/t5/help/faqpage/faq-category-id/posting?nobounce&lt;/A&gt; for posting code.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 07:48:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/substr/m-p/417329#M26863</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-30T07:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: substr</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/substr/m-p/417330#M26864</link>
      <description>&lt;P&gt;&lt;FONT size="3"&gt;&lt;STRONG&gt;&lt;SPAN style="color: navy; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Please find the code being used below.&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;STRONG&gt;&lt;SPAN style="color: navy; font-family: &amp;quot;Courier New&amp;quot;;"&gt;%macro&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt; macro_name(col_name);&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;FONT size="3"&gt;slen = length (&amp;amp;col_name);&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;i=&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="color: teal; font-family: &amp;quot;Courier New&amp;quot;;"&gt;0&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;FONT size="3"&gt;do until( i &amp;gt; slen);&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;substr(&amp;amp;col_name,i,slen) = &lt;/SPAN&gt;&lt;SPAN style="color: purple; font-family: &amp;quot;Courier New&amp;quot;;"&gt;"x"&lt;/SPAN&gt;&lt;SPAN style="color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN style="color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;i=i+&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="color: teal; font-family: &amp;quot;Courier New&amp;quot;;"&gt;1&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;FONT size="3"&gt;end;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;STRONG&gt;&lt;SPAN style="color: navy; font-family: &amp;quot;Courier New&amp;quot;;"&gt;%mend&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="color: black; font-family: &amp;quot;Courier New&amp;quot;;"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&amp;nbsp;table_name (drop=slen);&lt;/P&gt;&lt;P&gt;set mast_table;&lt;/P&gt;&lt;P&gt;%&lt;EM&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Courier New" size="3"&gt;macro_name&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/EM&gt;(Column1);&lt;/P&gt;&lt;P&gt;%&lt;EM&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Courier New" size="3"&gt;macro_name&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/EM&gt;(Column2);&lt;/P&gt;&lt;P&gt;drop i;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am facing issue with Column2.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 07:55:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/substr/m-p/417330#M26864</guid>
      <dc:creator>Sreelekha</dc:creator>
      <dc:date>2017-11-30T07:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: substr</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/substr/m-p/417333#M26865</link>
      <description>&lt;P&gt;Works for me:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro macro_name(col_name);
slen = length(&amp;amp;col_name);
i = 0;
do until (i &amp;gt; slen);
  substr(&amp;amp;col_name,i,slen) = "x";
  i = i + 1;
end;
%mend;

data test;
x1 = 'Sreelekha         ';
%macro_name(x1);
run;

proc print data=test noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;   x1        slen     i

xxxxxxxxx      9     10
&lt;/PRE&gt;
&lt;P&gt;If your results differ, post your example data as requested.&lt;/P&gt;
&lt;P&gt;Note that I used the "little running man" icon to post code, as shown in the link I gave you. Please follow advice.&lt;/P&gt;
&lt;P&gt;The main posting window changes code layout and makes copy/pasting difficult.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 08:02:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/substr/m-p/417333#M26865</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-30T08:02:53Z</dc:date>
    </item>
    <item>
      <title>Re: substr</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/substr/m-p/417334#M26866</link>
      <description>&lt;P&gt;I will use that.&lt;/P&gt;&lt;P&gt;Apologies for missing out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please try the string " Abcd Efghijklmn , Schools and Board of Management ".&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 08:24:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/substr/m-p/417334#M26866</guid>
      <dc:creator>Sreelekha</dc:creator>
      <dc:date>2017-11-30T08:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: substr</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/substr/m-p/417336#M26867</link>
      <description>&lt;P&gt;Look at the log. Your use of slen as the third parameter of the substr() function causes problems.&lt;/P&gt;
&lt;P&gt;Since you just want to overwrite a string from start to last non-blank character, you can simplify your macro a lot:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro macro_name(col_name);
&amp;amp;col_name = repeat("x",length(&amp;amp;col_name));
%mend;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which also has the advantage that no additional variables are created.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS the whole thing is now so simple that you will need a macro only when you want to reuse that code line a LOT. If you only need it for three variables, write the original code into the data step; makes for easier maintenance.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 08:46:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/substr/m-p/417336#M26867</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-30T08:46:00Z</dc:date>
    </item>
    <item>
      <title>Re: substr</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/substr/m-p/417340#M26868</link>
      <description>&lt;P&gt;You have fallen into the trap of many SAS programmers, in your immediate need to jump into macro programming, Macro is not the programming language.&amp;nbsp; Use Base SAS which is the programming language and you will find your coding far simpler:&lt;/P&gt;
&lt;PRE&gt;data have;
  length a $10;
  a="abc345kl"; output;
  a="tyhg222"; output;
  a="aa"; output;
run;

data want;
  set have;
  a=prxchange("s/[^A-Z ]/X/",-1,a);
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 09:16:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/substr/m-p/417340#M26868</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-30T09:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: substr</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/substr/m-p/417349#M26869</link>
      <description>&lt;P&gt;Hello Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; This worked.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need it for updating 20 tables, hence would be using it as a macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 10:18:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/substr/m-p/417349#M26869</guid>
      <dc:creator>Sreelekha</dc:creator>
      <dc:date>2017-11-30T10:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: substr</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/substr/m-p/417350#M26870</link>
      <description>&lt;P&gt;Thank you for the assistance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to update 20 tables and hence many columns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So. I would need a macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you..!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 10:20:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/substr/m-p/417350#M26870</guid>
      <dc:creator>Sreelekha</dc:creator>
      <dc:date>2017-11-30T10:20:08Z</dc:date>
    </item>
    <item>
      <title>Re: substr</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/substr/m-p/417352#M26872</link>
      <description>&lt;P&gt;Is there some pattern to the datasets/varaibles, or just all datasets in one library and all character varaibles?&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set sashelp.vcolumns (where=(libname="WORK"));
  by memname;
  if first.memname then call execute(cats('data work.',memname,'; set work.',memname,';'));
  if type="char" then call execute(name,'=prxchange("s/[^A-Z ]/X/",-1,',name,');');
  if last.memname then call execute(';run;');
run;&lt;/PRE&gt;
&lt;P&gt;This will run through every dataset in work and convert every character variable to the X's.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 10:34:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/substr/m-p/417352#M26872</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-30T10:34:38Z</dc:date>
    </item>
    <item>
      <title>Re: substr</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/substr/m-p/417397#M26878</link>
      <description>&lt;P&gt;There is a &lt;STRONG&gt;where&lt;/STRONG&gt; condition using which I will be filtering out the desired data. So, it is ideally 20 tables and the specified columns from each table&amp;nbsp;which have to be masked with 'XX..'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for this code as well :).&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 13:25:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/substr/m-p/417397#M26878</guid>
      <dc:creator>Sreelekha</dc:creator>
      <dc:date>2017-11-30T13:25:08Z</dc:date>
    </item>
  </channel>
</rss>

