<?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: Logic problem in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417137#M102454</link>
    <description>&lt;P&gt;Run the code and test it.&lt;/P&gt;
&lt;P&gt;Give the output data set different names and then use PROC COMPARE to check for any differences.&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>Wed, 29 Nov 2017 16:40:38 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-11-29T16:40:38Z</dc:date>
    <item>
      <title>Logic problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417116#M102445</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Variable name-cars&lt;/P&gt;&lt;P&gt;name of dataset-name&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to remove certain cars that make up &amp;lt;1% or &amp;lt;3% from a dataset.&lt;/P&gt;&lt;P&gt;I am not sure which of the following if then do end statement has a correct logic-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Code 1-&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;data work.name work.name_other; set work.name;&lt;/P&gt;&lt;P&gt;if cars not in ('BMW', 'AUDI', 'BENZ') then do;&lt;BR /&gt;if percent &amp;lt; 1 or count &lt;span class="lia-unicode-emoji" title=":red_heart:"&gt;❤️&lt;/span&gt; then output work.name_other; /*Pull cars that make up &amp;lt;1%&amp;nbsp;or &amp;lt;3*/&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;else output work.name;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Code 2-&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;data work.name work.name_other; set work.name;&lt;BR /&gt;if count &lt;span class="lia-unicode-emoji" title=":red_heart:"&gt;❤️&lt;/span&gt; and cars not in (&lt;SPAN&gt;'BMW', 'AUDI', 'BENZ'&lt;/SPAN&gt;)&lt;BR /&gt;then output work.name_other;&amp;nbsp;/*Pull cars that make up &amp;lt;1% or &amp;lt;3*/&lt;/P&gt;&lt;P&gt;else output work.name;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 16:12:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417116#M102445</guid>
      <dc:creator>Juli13</dc:creator>
      <dc:date>2017-11-29T16:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: Logic problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417120#M102446</link>
      <description>&lt;P&gt;LPT: format your code, it makes it easier to see if the indents match and if they don't you can find your errors more easily.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.name work.name_other;
	set work.name;

	if cars not in ('BMW', 'AUDI', 'BENZ') then
		do;
			if percent &amp;lt; 1 or count &amp;lt;3 then output work.name_other; /*Pull cars that make up &amp;lt;1% or &amp;lt;3*/
		end;
	else output work.name;
run;

data work.name work.name_other;
	set work.name;

	if count &amp;lt;3 and cars not in ('BMW', 'AUDI', 'BENZ') then output work.name_other; /*Pull cars that make up &amp;lt;1% or &amp;lt;3*/
	else output work.name;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;They aren't the same logic, but they're both valid SAS syntax.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's not clear what your actual question is - the logic for the if/then/do is correct in both cases, but since you didn't specify what you're logic should should be and what you have I can't comment beyond this.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 16:16:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417120#M102446</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-29T16:16:45Z</dc:date>
    </item>
    <item>
      <title>Re: Logic problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417125#M102447</link>
      <description>I am trying to remove certain cars that make up &amp;lt;1% or &amp;lt;3% from a dataset.&lt;BR /&gt;How can I edit Code 2 to match the logic?</description>
      <pubDate>Wed, 29 Nov 2017 16:22:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417125#M102447</guid>
      <dc:creator>Juli13</dc:creator>
      <dc:date>2017-11-29T16:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: Logic problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417131#M102448</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132081"&gt;@Juli13&lt;/a&gt; wrote:&lt;BR /&gt;I am trying to remove certain cars that make up &amp;lt;1% or &amp;lt;3% from a dataset.&lt;BR /&gt;How can I edit Code 2 to match the logic?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Add the part about COUNT, you currently have COUNT&amp;lt;3 or PERCENT&amp;lt;1 but your comment is regarding percentages...and anything less than 1% is also less than 3% so it's not clear logic, but easy enough to code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 16:30:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417131#M102448</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-29T16:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: Logic problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417132#M102449</link>
      <description>is this correct:&lt;BR /&gt;&lt;BR /&gt;data work.name work.name_other; set work.name;&lt;BR /&gt;if count &lt;span class="lia-unicode-emoji" title=":red_heart:"&gt;❤️&lt;/span&gt; and percent &amp;gt; 1 and cars not in ('BMW', 'AUDI', 'BENZ')&lt;BR /&gt;then output work.name_other; /*Pull cars that make up &amp;lt;1% or &amp;lt;3*/&lt;BR /&gt;else output work.name;&lt;BR /&gt;run;</description>
      <pubDate>Wed, 29 Nov 2017 16:33:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417132#M102449</guid>
      <dc:creator>Juli13</dc:creator>
      <dc:date>2017-11-29T16:33:18Z</dc:date>
    </item>
    <item>
      <title>Re: Logic problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417133#M102450</link>
      <description>data work.name work.name_other; set work.name;&lt;BR /&gt;if count &lt;span class="lia-unicode-emoji" title=":red_heart:"&gt;❤️&lt;/span&gt; and percent &amp;lt; 1 and cars not in ('BMW', 'AUDI', 'BENZ')&lt;BR /&gt;then output work.name_other; /*Pull cars that make up &amp;lt;1% or &amp;lt;3*/&lt;BR /&gt;else output work.name;&lt;BR /&gt;run;</description>
      <pubDate>Wed, 29 Nov 2017 16:36:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417133#M102450</guid>
      <dc:creator>Juli13</dc:creator>
      <dc:date>2017-11-29T16:36:28Z</dc:date>
    </item>
    <item>
      <title>Re: Logic problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417134#M102451</link>
      <description>&lt;P&gt;No, it doesn't match the first one:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if percent &amp;lt; 1 or count &amp;lt;3&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Nov 2017 16:37:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417134#M102451</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-29T16:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: Logic problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417136#M102453</link>
      <description>&lt;P&gt;&lt;SPAN&gt;data work.name work.name_other; set work.name;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if count &lt;span class="lia-unicode-emoji" title=":red_heart:"&gt;❤️&lt;/span&gt; and percent &amp;lt; 1 and cars not in ('BMW', 'AUDI', 'BENZ')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;then output work.name_other; /*Pull cars that make up &amp;lt;1% or &amp;lt;3*/&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;else output work.name;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 16:38:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417136#M102453</guid>
      <dc:creator>Juli13</dc:creator>
      <dc:date>2017-11-29T16:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: Logic problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417137#M102454</link>
      <description>&lt;P&gt;Run the code and test it.&lt;/P&gt;
&lt;P&gt;Give the output data set different names and then use PROC COMPARE to check for any differences.&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>Wed, 29 Nov 2017 16:40:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417137#M102454</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-29T16:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: Logic problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417138#M102455</link>
      <description>is the logic correct?</description>
      <pubDate>Wed, 29 Nov 2017 16:42:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417138#M102455</guid>
      <dc:creator>Juli13</dc:creator>
      <dc:date>2017-11-29T16:42:40Z</dc:date>
    </item>
    <item>
      <title>Re: Logic problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417139#M102456</link>
      <description>&lt;P&gt;The logic is the same. Is it correct? No idea.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 16:44:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417139#M102456</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-29T16:44:48Z</dc:date>
    </item>
    <item>
      <title>Re: Logic problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417144#M102458</link>
      <description>&lt;P&gt;Are your Percent values multiplied by 100?&amp;nbsp;&amp;nbsp;Example: 0.25 or 25? Depending on how you created percent you might have percents in the 0 to 1 range not the 0 to 100 range and therefore your "Percent &amp;lt;1" may behave incorrectly.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 16:54:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417144#M102458</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-11-29T16:54:04Z</dc:date>
    </item>
    <item>
      <title>Re: Logic problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417145#M102459</link>
      <description>Thank you so much ballardw! I couldn't understand why code 1 was behaving incorrectly. They are in % format. Thanks!</description>
      <pubDate>Wed, 29 Nov 2017 16:56:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417145#M102459</guid>
      <dc:creator>Juli13</dc:creator>
      <dc:date>2017-11-29T16:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: Logic problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417148#M102460</link>
      <description>&lt;P&gt;It's also bad form to use the same output name. Try using different ones otherwise you destroy your source data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;data &lt;STRONG&gt;work.name&lt;/STRONG&gt; work.name_other; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;set work.name;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if count &lt;span class="lia-unicode-emoji" title=":red_heart:"&gt;❤️&lt;/span&gt; and percent &amp;lt; 1 and cars not in ('BMW', 'AUDI', 'BENZ')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;then output work.name_other; /*Pull cars that make up &amp;lt;1% or &amp;lt;3*/&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;else output work.name;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Once you run this once, and it replaces your original data so you cannot re-run this step without first recreating the original NAME data set.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 16:58:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417148#M102460</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-29T16:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: Logic problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417159#M102462</link>
      <description>&lt;P&gt;It helps if you state what's happening, for example you never said anything was 'behaving incorrectly', all you were asking was "is the logic right" and didn't provide any sample data. If you'd provided sample data this would have been answered in the first example.&amp;nbsp; And this is why I said the code is the same, but I can't answer if the logic was correct, because it clearly wasn't....&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132081"&gt;@Juli13&lt;/a&gt; wrote:&lt;BR /&gt;Thank you so much ballardw! I couldn't understand why code 1 was behaving incorrectly. They are in % format. Thanks!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 17:12:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-problem/m-p/417159#M102462</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-29T17:12:19Z</dc:date>
    </item>
  </channel>
</rss>

