<?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: Cleaning a text variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Cleaning-a-text-variable/m-p/781986#M249258</link>
    <description>&lt;P&gt;I think this calls for PRXCHANGE. If someone notices an issue with my regex, please feel free to correct it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Errors may pop up depending on whether the words are consistently spelled the way you showed them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
var = "4 GRAMS ONLY TODAY, 15 OUNCE ONLY TODAY";
run;

data want;
	set have;
		want_var = prxchange("s/\s*?(ONLY TODAY)\s*?//", -1, var);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs var want_var 
1 4 GRAMS ONLY TODAY, 15 OUNCE ONLY TODAY 4 GRAMS, 15 OUNCE 
&lt;/PRE&gt;
&lt;P&gt;The&lt;/P&gt;
&lt;PRE&gt;\s*?&lt;/PRE&gt;
&lt;P&gt;checks for zero or more spaces before or after the phrase ONLY TODAY.&lt;/P&gt;</description>
    <pubDate>Tue, 23 Nov 2021 15:53:48 GMT</pubDate>
    <dc:creator>maguiremq</dc:creator>
    <dc:date>2021-11-23T15:53:48Z</dc:date>
    <item>
      <title>Cleaning a text variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cleaning-a-text-variable/m-p/781979#M249253</link>
      <description>&lt;P&gt;I have a variable that contains details on how much medicine was administered for each patient during a stay at the hospital and I need to clean some observations.&lt;/P&gt;
&lt;P&gt;Examples of clean observations are: 2 GRAMS, 20 OUNCE&lt;/P&gt;
&lt;P&gt;for these clean examples, I create two variables one for the quantity and one for the unit.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But some observations are: 4 GRAMS ONLY TODAY, 15 OUNCE ONLY TODAY.&lt;/P&gt;
&lt;P&gt;For these examples, I need to remove ONLY TODAY, and then I can separate the quantity and unit values using COMPRESS&lt;/P&gt;
&lt;P&gt;quantity=compress(DrugQuantity,"1234567890./","k");&lt;BR /&gt;unit=compress(DrugQuantity,"ABCDEFGHIJKLMNOPQRSTUVWXYZ ","k");&lt;/P&gt;
&lt;P&gt;How can I remove all those ONLY&amp;nbsp;TODAY parts from my original variable or from my compressed unit variable? I appreciate your suggestions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Nov 2021 15:44:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cleaning-a-text-variable/m-p/781979#M249253</guid>
      <dc:creator>Emma_at_SAS</dc:creator>
      <dc:date>2021-11-23T15:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: Cleaning a text variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cleaning-a-text-variable/m-p/781986#M249258</link>
      <description>&lt;P&gt;I think this calls for PRXCHANGE. If someone notices an issue with my regex, please feel free to correct it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Errors may pop up depending on whether the words are consistently spelled the way you showed them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
var = "4 GRAMS ONLY TODAY, 15 OUNCE ONLY TODAY";
run;

data want;
	set have;
		want_var = prxchange("s/\s*?(ONLY TODAY)\s*?//", -1, var);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs var want_var 
1 4 GRAMS ONLY TODAY, 15 OUNCE ONLY TODAY 4 GRAMS, 15 OUNCE 
&lt;/PRE&gt;
&lt;P&gt;The&lt;/P&gt;
&lt;PRE&gt;\s*?&lt;/PRE&gt;
&lt;P&gt;checks for zero or more spaces before or after the phrase ONLY TODAY.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Nov 2021 15:53:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cleaning-a-text-variable/m-p/781986#M249258</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-11-23T15:53:48Z</dc:date>
    </item>
    <item>
      <title>Re: Cleaning a text variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cleaning-a-text-variable/m-p/781997#M249261</link>
      <description>&lt;P&gt;Thanks very much&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281770"&gt;@maguiremq&lt;/a&gt;.&amp;nbsp;your solution works perfectly! Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Nov 2021 16:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cleaning-a-text-variable/m-p/781997#M249261</guid>
      <dc:creator>Emma_at_SAS</dc:creator>
      <dc:date>2021-11-23T16:39:14Z</dc:date>
    </item>
  </channel>
</rss>

