<?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 do i strip out specific characters from this data set variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-strip-out-specific-characters-from-this-data-set/m-p/887900#M350796</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/252358"&gt;@Hello_there&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks, this worked out great&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;One thing to remember is that TRANWRD() does not totally remove the strings. In stead it is replacing them with a single space. If you need to totally remove the strings you need to use TRANSTRN() as that can actually replace the target string with nothing.&amp;nbsp; But to generate the nothing you need to use TRIMN() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why?&lt;/P&gt;
&lt;P&gt;SAS stores character strings as fixed length that is padded with spaces.&amp;nbsp; The shortest possible character variable is 1 character.&amp;nbsp; So even if you type '' in your code TRANWRD() is still going to see ' ' as the text to be substituted.&amp;nbsp; Similarly if you use TRIM() to remove trailing spaces you still end up with a string that is at least one character long.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But when SAS introduced TRIMN() and TRANSTRN() functions they allowed them to generate and receive strings of length zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date=transtrn(date,'-UNK',trimn(' '));&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 04 Aug 2023 15:22:45 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-08-04T15:22:45Z</dc:date>
    <item>
      <title>How do i strip out specific characters from this data set variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-strip-out-specific-characters-from-this-data-set/m-p/887891#M350790</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a data manipulation practice exercise.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I strip out all instances of "UNK", "000", "00" efficiently?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length date $12;
	input date $;
datalines;
2017-02-23
2017-02-UNK
2017-UNK-UNK
UNK-UNK-UNK
2017-02-00
2017-00-00
0000-00-00
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Want:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Hello_there_1-1691160809394.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/86446i7F32CAA0A82F348E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Hello_there_1-1691160809394.png" alt="Hello_there_1-1691160809394.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2023 14:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-strip-out-specific-characters-from-this-data-set/m-p/887891#M350790</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-08-04T14:53:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do i strip out specific characters from this data set variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-strip-out-specific-characters-from-this-data-set/m-p/887894#M350792</link>
      <description>&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;data have;
length date $12;
	input date $;
   date=tranwrd(date,'0000','');
   date=tranwrd(date,'-00','');
   date=tranwrd(date,'-UNK','');
   date=tranwrd(date,'UNK','');
datalines;
2017-02-23
2017-02-UNK
2017-UNK-UNK
UNK-UNK-UNK
2017-02-00
2017-00-00
0000-00-00
;
run;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/252358"&gt;@Hello_there&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a data manipulation practice exercise.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I strip out all instances of "UNK", "000", "00" efficiently?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length date $12;
	input date $;
datalines;
2017-02-23
2017-02-UNK
2017-UNK-UNK
UNK-UNK-UNK
2017-02-00
2017-00-00
0000-00-00
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Want:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Hello_there_1-1691160809394.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/86446i7F32CAA0A82F348E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Hello_there_1-1691160809394.png" alt="Hello_there_1-1691160809394.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2023 15:02:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-strip-out-specific-characters-from-this-data-set/m-p/887894#M350792</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-04T15:02:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do i strip out specific characters from this data set variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-strip-out-specific-characters-from-this-data-set/m-p/887895#M350793</link>
      <description>Thanks, this worked out great</description>
      <pubDate>Fri, 04 Aug 2023 15:04:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-strip-out-specific-characters-from-this-data-set/m-p/887895#M350793</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-08-04T15:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do i strip out specific characters from this data set variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-strip-out-specific-characters-from-this-data-set/m-p/887900#M350796</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/252358"&gt;@Hello_there&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks, this worked out great&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;One thing to remember is that TRANWRD() does not totally remove the strings. In stead it is replacing them with a single space. If you need to totally remove the strings you need to use TRANSTRN() as that can actually replace the target string with nothing.&amp;nbsp; But to generate the nothing you need to use TRIMN() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why?&lt;/P&gt;
&lt;P&gt;SAS stores character strings as fixed length that is padded with spaces.&amp;nbsp; The shortest possible character variable is 1 character.&amp;nbsp; So even if you type '' in your code TRANWRD() is still going to see ' ' as the text to be substituted.&amp;nbsp; Similarly if you use TRIM() to remove trailing spaces you still end up with a string that is at least one character long.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But when SAS introduced TRIMN() and TRANSTRN() functions they allowed them to generate and receive strings of length zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date=transtrn(date,'-UNK',trimn(' '));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Aug 2023 15:22:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-strip-out-specific-characters-from-this-data-set/m-p/887900#M350796</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-04T15:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do i strip out specific characters from this data set variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-strip-out-specific-characters-from-this-data-set/m-p/887901#M350797</link>
      <description>Thanks for making me aware of this.</description>
      <pubDate>Fri, 04 Aug 2023 15:24:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-strip-out-specific-characters-from-this-data-set/m-p/887901#M350797</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-08-04T15:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do i strip out specific characters from this data set variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-strip-out-specific-characters-from-this-data-set/m-p/887959#M350821</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Deleting a substring from a SAS string&lt;/STRONG&gt; &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;Inserting a substring into a SAS string &lt;BR /&gt;By Leonid Batkhan on SAS Users February 15, 2021&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/sgf/2021/02/15/inserting-a-substring-into-a-sas-string/" target="_blank"&gt;https://blogs.sas.com/content/sgf/2021/02/15/inserting-a-substring-into-a-sas-string/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2023 21:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-strip-out-specific-characters-from-this-data-set/m-p/887959#M350821</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2023-08-04T21:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: How do i strip out specific characters from this data set variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-strip-out-specific-characters-from-this-data-set/m-p/887992#M350829</link>
      <description>&lt;P&gt;Here a RegEx approach.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  length date $12;
  input date $;
  date=prxchange('s/-?(unk|00+)-?//oi',-1,strip(date));
  datalines;
2017-02-23
2017-02-UNK
2017-UNK-UNK
UNK-UNK-UNK
2017-02-00
2017-00-00
0000-00-00
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Aug 2023 23:41:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-strip-out-specific-characters-from-this-data-set/m-p/887992#M350829</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-08-04T23:41:08Z</dc:date>
    </item>
  </channel>
</rss>

