<?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: Why is my code not flagging variables properly? in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Why-is-my-code-not-flagging-variables-properly/m-p/279854#M7931</link>
    <description>&lt;P&gt;Rethink your else statement.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 23 Jun 2016 20:54:57 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-06-23T20:54:57Z</dc:date>
    <item>
      <title>Why is my code not flagging variables properly?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Why-is-my-code-not-flagging-variables-properly/m-p/279841#M7930</link>
      <description>&lt;P&gt;I have a data set and I am trying to flag all variables that have the word "treatment" or "tx" with a 1 else 0. However, there are some observations which have the following description: "Supplies-treatment" or "supplies-tx". For these, I DO NOT want them to be flagged with a 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data flagtx;&lt;BR /&gt;set flagtxdc;&lt;BR /&gt;if prxmatch("m/tx|treatment|treat/oi",description) &amp;gt; 0 then tx=1;&lt;BR /&gt;else tx=0;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this works perfectly! When I run a proc freq I see that there are 33314 obs flagged with a 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But then I want to unflag all the descriptions that have the word "supplies" in them. In order to accomplish this I thought I could use a prxmatch as above but on the new dataset I just created with all the words "treatment" flagged with 1, and when it came across any descriptions with "supplies" it would flag it as a 0. I used this code next after running the above code to accomplish the aforementioned:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data flagtxsupplies;&lt;BR /&gt;set flagtx;&lt;BR /&gt;if prxmatch("m/supplies/oi",description) &amp;gt; 0 then tx=0;&lt;BR /&gt;else tx=1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I run a proc freq, I see that it has incorrectly flagged my variables somehow. Instead of having LESS than 33314 obs flagged with a 1 (which should be the case because I am eliminating "supplies-treatment") I actually have MORE obs that have been flagged with a 1. 64174 to be exact!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did a proc print on 100 obs but everything looks good..what is going on?? What is my code doing exactly?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2016 20:21:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Why-is-my-code-not-flagging-variables-properly/m-p/279841#M7930</guid>
      <dc:creator>christinagting0</dc:creator>
      <dc:date>2016-06-23T20:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my code not flagging variables properly?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Why-is-my-code-not-flagging-variables-properly/m-p/279854#M7931</link>
      <description>&lt;P&gt;Rethink your else statement.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2016 20:54:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Why-is-my-code-not-flagging-variables-properly/m-p/279854#M7931</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-23T20:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my code not flagging variables properly?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Why-is-my-code-not-flagging-variables-properly/m-p/279896#M7932</link>
      <description>&lt;P&gt;Your second step overwrites tx for every obs. So the end result is just the last test, i.e. anything not supplies is flagged.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a single step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data flagtx;
set flagtxdc;
tx = 0;
if prxmatch("m/tx|treatment|treat/oi", description) &amp;gt; 0 then 
	if prxmatch("m/supplies/oi", description) = 0 then tx = 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Jun 2016 03:35:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Why-is-my-code-not-flagging-variables-properly/m-p/279896#M7932</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-06-24T03:35:07Z</dc:date>
    </item>
  </channel>
</rss>

