<?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: data step rule does not work for only one row in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/data-step-rule-does-not-work-for-only-one-row/m-p/273554#M54527</link>
    <description>&lt;P&gt;I'm not sure you need to change dxn to 1 when 0 is the accurate value. &amp;nbsp;This should work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data freq2;&lt;/P&gt;
&lt;P&gt;set freq;&lt;/P&gt;
&lt;P&gt;if (dxn=1) or (dxn=0 and percent=100);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 27 May 2016 10:56:04 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-05-27T10:56:04Z</dc:date>
    <item>
      <title>data step rule does not work for only one row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-rule-does-not-work-for-only-one-row/m-p/273486#M54507</link>
      <description>&lt;P&gt;Hi, I'm using SAS 9.3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I generated frequencies of a variable "dxn" by ID using proc freq (frequencies generated attached).&lt;/P&gt;&lt;P&gt;I only want to keep&amp;nbsp;the frequency of dxn when it is 1 but I have a few IDs with 100% dxn=0.&amp;nbsp;I tried changing this by assigning dxn=1 and percent=0 whenever dxn=0 and percent=100. This worked for all rows except one (ID=78).&amp;nbsp;I have tried debugging and SAS does acknowledge that dxn=0 and precent=100 for ID 78 but it does not change the values as requested. Why is this happenning??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data freq2;
set freq;
if dxn=0 and percent=100 then do; 
dxn=1;
percent=0;
drop if dxn=0;
end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2016 04:38:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-rule-does-not-work-for-only-one-row/m-p/273486#M54507</guid>
      <dc:creator>JoannaL</dc:creator>
      <dc:date>2016-05-27T04:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: data step rule does not work for only one row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-rule-does-not-work-for-only-one-row/m-p/273491#M54510</link>
      <description>&lt;P&gt;Your using the drop statement incorrectly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Drop refers to to dropping a variable not an observation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to delete an observation use delete.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;If dxn=0 then delete;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'm not 100% sure what you want though, is it to see 0/1 for all IDs? If so try the SPARSE option in your proc freq and then delete the 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc freq data=have;
Table id*dxn / out =want (where =(dxn=1)) sparse;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 May 2016 05:02:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-rule-does-not-work-for-only-one-row/m-p/273491#M54510</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-27T05:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: data step rule does not work for only one row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-rule-does-not-work-for-only-one-row/m-p/273509#M54516</link>
      <description>&lt;P&gt;Thanks Reeza, I just want the 1s and your solution will give me the 1s. Yeah I made a mistake and copied a wrong line of code. It was supposed to be if dxn=0 then delete.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, it doesn't answer why there is a chance that a data step works for some rows and not for others. This seems to imply that other datasets may be wrongly processed too.&amp;nbsp;&lt;/P&gt;&lt;P&gt;i.e. from my code it is clear that dxn will be changed to 1 and percent changed to 0 whenever dxn=0 and percent=100. But if you try running the code, row 78 which meets the criteria does not process and stays as dxn=0, percent=100.&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; freq2&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;freq&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;dx&lt;/SPAN&gt;n&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;0&lt;/SPAN&gt; and percent&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;100&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; do&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; 
&lt;SPAN class="token number"&gt;dx&lt;/SPAN&gt;n&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
percent&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;0&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
end&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2016 06:37:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-rule-does-not-work-for-only-one-row/m-p/273509#M54516</guid>
      <dc:creator>JoannaL</dc:creator>
      <dc:date>2016-05-27T06:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: data step rule does not work for only one row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-rule-does-not-work-for-only-one-row/m-p/273526#M54523</link>
      <description>&lt;P&gt;Could it be a rounding issue? &amp;nbsp;There are times when a calculation results in a value which is very small, say:&lt;/P&gt;
&lt;P&gt;pcent=100.00000000000001&lt;/P&gt;
&lt;P&gt;It can be that you don't see that really small part (there are other posts here that go into detail as to why this happens), but when you do logical checks 100 != 100.0000000000001, so it fails. &amp;nbsp;I would suggest you always use a rounding in these cases:&lt;/P&gt;
&lt;P&gt;if dxn=0 and floor(percent)=100...&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2016 08:46:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-rule-does-not-work-for-only-one-row/m-p/273526#M54523</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-05-27T08:46:41Z</dc:date>
    </item>
    <item>
      <title>Re: data step rule does not work for only one row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-rule-does-not-work-for-only-one-row/m-p/273554#M54527</link>
      <description>&lt;P&gt;I'm not sure you need to change dxn to 1 when 0 is the accurate value. &amp;nbsp;This should work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data freq2;&lt;/P&gt;
&lt;P&gt;set freq;&lt;/P&gt;
&lt;P&gt;if (dxn=1) or (dxn=0 and percent=100);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2016 10:56:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-rule-does-not-work-for-only-one-row/m-p/273554#M54527</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-05-27T10:56:04Z</dc:date>
    </item>
    <item>
      <title>Re: data step rule does not work for only one row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-rule-does-not-work-for-only-one-row/m-p/273555#M54528</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76609"&gt;@JoannaL﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I second RW9's idea that this is most likely a rounding issue. You can check this, if you like, with the following PROC FREQ step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=freq;
where percent&amp;gt;99.99;
format percent hex16.;
tables percent;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Any values of PERCENT other than&amp;nbsp;4059000000000000 (hexadecimal floating-point representations) in the output of this step would represent numbers different from 100.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using the FLOOR function, as suggested by RW9, might work (due to implied fuzzing). Personally, I prefer the ROUND function. For your data this should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if dxn=0 and round(percent, .001)=100 then do; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or, even simpler:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if dxn=0 and percent&amp;gt;99.99 then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, I would recommend to make sure that the absolute numbers in variable Frequency (if they are kept in dataset FREQ2) are consistent with the modified DXN values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Removed the remark about the DELETE statement after realizing that you removed it from the DO-END block where it was (as "drop ...") in your initial post.&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2016 11:09:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-rule-does-not-work-for-only-one-row/m-p/273555#M54528</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-05-27T11:09:19Z</dc:date>
    </item>
    <item>
      <title>Re: data step rule does not work for only one row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-rule-does-not-work-for-only-one-row/m-p/273557#M54530</link>
      <description>&lt;P&gt;Why not take a step back and ask the question. What are you actually trying to do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If DXn is a 1/0 variable and what you want is the COUNT and PERCENT of records that are 1 per ID value you can do it in one step from your original data by using PROC MEANS (summary).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have nway ;
   class id ;
   var dxn ;
   output out=want sum=count mean=percent ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2016 11:13:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-rule-does-not-work-for-only-one-row/m-p/273557#M54530</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-05-27T11:13:01Z</dc:date>
    </item>
    <item>
      <title>Re: data step rule does not work for only one row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-rule-does-not-work-for-only-one-row/m-p/274847#M54903</link>
      <description>&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the answers. I've finally found the time to test them out and they all work.&amp;nbsp;&lt;BR /&gt;It was a rounding issue after all and all the solutions provided with that gave me what I wanted to do with the codes.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tom suggested going a step back and yes, Reeza has actually suggested a solution to what I originally intended.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, thanks again everyone!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jun 2016 04:14:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-rule-does-not-work-for-only-one-row/m-p/274847#M54903</guid>
      <dc:creator>JoannaL</dc:creator>
      <dc:date>2016-06-03T04:14:28Z</dc:date>
    </item>
  </channel>
</rss>

