<?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: Replace characters in many columns when creating a table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-characters-in-many-columns-when-creating-a-table/m-p/836529#M330755</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/404650"&gt;@MILKYLOVE&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The problem with this solution is that not all the variables of each array list are of the same data type.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Therefore I am getting errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The program also does not recognise '-'&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That rule doesn't make sense for a numeric variable. In SAS, the variable would not be able to have - characters in the first place. If you need to convert types that's a more complex rule.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cleaning data is always a somewhat tedious process. You have two options, for each rule loop through the variables, or for each variable loop through the applicable rules. It's easier to do the first one in SAS via arrays.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 03 Oct 2022 15:07:23 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-10-03T15:07:23Z</dc:date>
    <item>
      <title>Replace characters in many columns when creating a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-characters-in-many-columns-when-creating-a-table/m-p/836479#M330735</link>
      <description>&lt;P&gt;Hello guys,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am creating a new table 'Result', using different columns from a table 'Person'.&lt;/P&gt;&lt;P&gt;I have been provided with different rules to apply on these columns:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;R16:&amp;nbsp;Delete character "-"&lt;/P&gt;&lt;P&gt;R17: Delete character "*"&lt;/P&gt;&lt;P&gt;R18: Delete character "."&lt;/P&gt;&lt;P&gt;R19: Delete Numerical Letters&lt;/P&gt;&lt;P&gt;R20:&amp;nbsp;Delete character "0"&lt;/P&gt;&lt;P&gt;R21: Delete character "?"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;These rules have to be applied to several columns. So I cannot use 'Compress' since I will have to do it on each column every time. Is there a proc format that I can apply for deleting characters?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MILKYLOVE_1-1664785234929.png" style="width: 525px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75814iD765F3AE8950F919/image-dimensions/525x134?v=v2" width="525" height="134" role="button" title="MILKYLOVE_1-1664785234929.png" alt="MILKYLOVE_1-1664785234929.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2022 08:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-characters-in-many-columns-when-creating-a-table/m-p/836479#M330735</guid>
      <dc:creator>MILKYLOVE</dc:creator>
      <dc:date>2022-10-03T08:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: Replace characters in many columns when creating a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-characters-in-many-columns-when-creating-a-table/m-p/836482#M330736</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's not "replace", it's delete !&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See here :&lt;/P&gt;
&lt;P&gt;Deleting a substring from a SAS string&lt;BR /&gt;By Leonid Batkhan on SAS Users February 22, 2021&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/sgf/2021/02/22/deleting-a-substring-from-a-sas-string/" target="_blank"&gt;https://blogs.sas.com/content/sgf/2021/02/22/deleting-a-substring-from-a-sas-string/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For more of this string-based stuff ,&lt;/P&gt;
&lt;P&gt;see &lt;A href="https://blogs.sas.com/content/?s=Leonid+Batkhan+string" target="_blank"&gt;https://blogs.sas.com/content/?s=Leonid+Batkhan+string&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;deleting, inserting, replacing, ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;
&lt;DIV id="ConnectiveDocSignExtentionInstalled" data-extension-version="1.0.4"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Mon, 03 Oct 2022 08:45:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-characters-in-many-columns-when-creating-a-table/m-p/836482#M330736</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2022-10-03T08:45:25Z</dc:date>
    </item>
    <item>
      <title>Re: Replace characters in many columns when creating a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-characters-in-many-columns-when-creating-a-table/m-p/836485#M330737</link>
      <description>&lt;P&gt;Actually this does not help me because these are examples where they are using strings, and mostly have only 1/2 lines to treat.&lt;/P&gt;&lt;P&gt;In my case, I have many columns to apply the same treatment and it will not be efficient to do it on each column every time.&lt;/P&gt;&lt;P&gt;That's why I am asking if there is a proc format or another way to automate this step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2022 09:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-characters-in-many-columns-when-creating-a-table/m-p/836485#M330737</guid>
      <dc:creator>MILKYLOVE</dc:creator>
      <dc:date>2022-10-03T09:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: Replace characters in many columns when creating a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-characters-in-many-columns-when-creating-a-table/m-p/836488#M330738</link>
      <description>&lt;P&gt;I think it does help you :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* suppress hyphen        (- ) from ABC vars R1 - R4 */
/* suppress question mark (?) from XYZ vars R8 - R10 */
data work.WANT;
   SUB1 = '-';
   SUB2 = '?';
   set work.HAVE;
   array ABC{4} $ R1 R2 R3 R4;
   array XYZ{3} $ R8 R9 R10  ;
   do i = 1 to dim(ABC);
     ABC(i) = transtrn(ABC(i),SUB1,trimn(''));
   end;
   do i = 1 to dim(XYZ);
     XYZ(i) = transtrn(XYZ(i),SUB2,trimn(''));
   end;
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2022 16:06:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-characters-in-many-columns-when-creating-a-table/m-p/836488#M330738</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2022-10-03T16:06:42Z</dc:date>
    </item>
    <item>
      <title>Re: Replace characters in many columns when creating a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-characters-in-many-columns-when-creating-a-table/m-p/836497#M330740</link>
      <description>&lt;P&gt;The problem with this solution is that not all the variables of each array list are of the same data type.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Therefore I am getting errors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The program also does not recognise '-'&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2022 11:36:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-characters-in-many-columns-when-creating-a-table/m-p/836497#M330740</guid>
      <dc:creator>MILKYLOVE</dc:creator>
      <dc:date>2022-10-03T11:36:24Z</dc:date>
    </item>
    <item>
      <title>Re: Replace characters in many columns when creating a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-characters-in-many-columns-when-creating-a-table/m-p/836500#M330742</link>
      <description>&lt;P&gt;First, you will need to clarify the request.&amp;nbsp; Probably, you should be processing character variables only.&amp;nbsp; But that's "probably", not a guarantee.&amp;nbsp; For example, numeric variables can take on a value of 0.&amp;nbsp; And they can appear to be a letter when they take on special numeric values like .A, .B, etc.&amp;nbsp; So make sure you are supposed to process character variables only.&amp;nbsp; And finally make sure that you are supposed to remove the offending characters, rather than replace them with blanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having done that, it's easy to set up an array containing all the character variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array just_these {*} _character_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then move through the array, using the functions of your choice.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2022 11:48:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-characters-in-many-columns-when-creating-a-table/m-p/836500#M330742</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-10-03T11:48:45Z</dc:date>
    </item>
    <item>
      <title>Re: Replace characters in many columns when creating a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-characters-in-many-columns-when-creating-a-table/m-p/836503#M330744</link>
      <description>&lt;P&gt;I concur with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;Also, in your original post, you have this :&amp;nbsp;&lt;BR /&gt;&lt;SPAN&gt;R19: Delete Numerical Letters&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;What are Numerical Letters, is this "digits" in a character string??&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Suppressing digits can be done with COMPRESS function, like here :&lt;BR /&gt;(but there are other modifiers and arguments to the COMPRESS function that can accomplish the same)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
   LENGTH x $ 100 y $ 100;
   x='Hearing @ mooing and 3 seeing cows ! tend to occur 77 , together';
   y=compress(x, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ', 'ki');
   put y=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Best,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Koen&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2022 12:13:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-characters-in-many-columns-when-creating-a-table/m-p/836503#M330744</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2022-10-03T12:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: Replace characters in many columns when creating a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-characters-in-many-columns-when-creating-a-table/m-p/836519#M330752</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/404650"&gt;@MILKYLOVE&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The problem with this solution is that not all the variables of each array list are of the same data type.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Therefore I am getting errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The program also does not recognise '-'&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Which of your variables is of a "different type" that needs any of those rules applied. All of your rules involve text.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you mean by "does not recognise '-' "? If you are getting an error then show us the LOG of the actual code you ran. Copy the Log for the step with all the code and all the messages. On the forum open a text box with the &amp;lt;/&amp;gt; icon and paste the text.&lt;/P&gt;
&lt;P&gt;The text box is important as it will display any of the diagnostics that SAS often supplies correctly where the main message windows will reformat text making them less useful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, provide actual example data. Instructions here: &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; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;/&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2022 14:43:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-characters-in-many-columns-when-creating-a-table/m-p/836519#M330752</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-10-03T14:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: Replace characters in many columns when creating a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-characters-in-many-columns-when-creating-a-table/m-p/836529#M330755</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/404650"&gt;@MILKYLOVE&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The problem with this solution is that not all the variables of each array list are of the same data type.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Therefore I am getting errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The program also does not recognise '-'&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That rule doesn't make sense for a numeric variable. In SAS, the variable would not be able to have - characters in the first place. If you need to convert types that's a more complex rule.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cleaning data is always a somewhat tedious process. You have two options, for each rule loop through the variables, or for each variable loop through the applicable rules. It's easier to do the first one in SAS via arrays.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2022 15:07:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-characters-in-many-columns-when-creating-a-table/m-p/836529#M330755</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-10-03T15:07:23Z</dc:date>
    </item>
  </channel>
</rss>

