<?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: Array to flag values in certain range(s) only flags within rounding error? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-to-flag-values-in-certain-range-s-only-flags-within/m-p/835206#M330184</link>
    <description>&lt;P&gt;Just to double confirm, your condition is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;flag elements which are either greater then 0.35 or less than -0.35&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Mon, 26 Sep 2022 15:47:10 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2022-09-26T15:47:10Z</dc:date>
    <item>
      <title>Array to flag values in certain range(s) only flags within rounding error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-flag-values-in-certain-range-s-only-flags-within/m-p/835198#M330177</link>
      <description>&lt;P&gt;Hi there, so I'm trying to use this little doo-wop to flag variables that have values within certain range(s) (&amp;gt;= |.35|):&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data flags (drop= i); set data; 
array factor {10} factor1-factor10; 
array place {10} place1-place10; 
do i = 1 to 10; 
	place{i} = 0; 
	if factor{i} &amp;lt; .35 and factor{i} &amp;gt; -.35 then place{i} = 1; /* &amp;gt;= |.35| threshold is somewhat arbitrary, 
																	may be changed */ 
end; 
noload_ct = sum(of place1-place10); 
noload = 0; 
if noload_ct = 10 then noload = 1; 
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Now, I've done this before with other data, and it appeared to work as expected.&amp;nbsp; But in this particular instance, upon inspection of the values I'm trying to filter, it &lt;STRONG&gt;is&lt;/STRONG&gt; flagging cases that are &lt;SPAN&gt;&lt;EM&gt;≈&lt;/EM&gt;&lt;/SPAN&gt; .346, which are obviously are not &amp;gt;=|.35|.&amp;nbsp; Such "close" cases perhaps simply did not exist in prior use of this approach; hence I did not notice.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I suppose I can chalk this up to some sort of rounding that is going on behind the scenes.&amp;nbsp; For my present purposes, I imagine this is fine, but my concern is still that it would be technically inaccurate to say that I used a threshold of &amp;gt;= .35, when the output retains values that are technically, say, &amp;gt; .345 (or whatever it is that's happening behind the scenes).&amp;nbsp; That is, if someone replicated the analysis with the same data, they might observe this inconsistency, and say, awesome_opossum, &lt;EM&gt;"you're wrong, and a liar; how dare you."&lt;/EM&gt;, which is principally silly enough that it is something I wish to avoid.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have an explanation for this, that I can at least include in a footnote (e.g. is it actually &amp;gt; .345 -- values rounded to the hundredth?), or any recommendations?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For clarification:&amp;nbsp; I'm making two lists: one is a list of all the items (rows) that are &amp;gt;= |.35| on at least one variable; the other is a list of items (rows) that are &amp;lt; |.35| on all the variables. Items (rows) with a highest value of |.346| on any variable end up on the list that is supposed to be &amp;gt;= |.35|.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 16:18:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-flag-values-in-certain-range-s-only-flags-within/m-p/835198#M330177</guid>
      <dc:creator>awesome_opossum</dc:creator>
      <dc:date>2022-09-26T16:18:02Z</dc:date>
    </item>
    <item>
      <title>Re: Array to flag values in certain range(s) only flags within rounding error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-flag-values-in-certain-range-s-only-flags-within/m-p/835202#M330181</link>
      <description>&lt;P&gt;Your condition is wrong.&lt;/P&gt;
&lt;P&gt;Should be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt; factor{i} &amp;gt; .35 and factor{i} &amp;lt; -.35&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 15:36:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-flag-values-in-certain-range-s-only-flags-within/m-p/835202#M330181</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-09-26T15:36:15Z</dc:date>
    </item>
    <item>
      <title>Re: Array to flag values in certain range(s) only flags within rounding error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-flag-values-in-certain-range-s-only-flags-within/m-p/835203#M330182</link>
      <description>&lt;P&gt;I narrated it as the opposite; the inaccurate flagging remains the issue.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 15:37:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-flag-values-in-certain-range-s-only-flags-within/m-p/835203#M330182</guid>
      <dc:creator>awesome_opossum</dc:creator>
      <dc:date>2022-09-26T15:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: Array to flag values in certain range(s) only flags within rounding error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-flag-values-in-certain-range-s-only-flags-within/m-p/835206#M330184</link>
      <description>&lt;P&gt;Just to double confirm, your condition is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;flag elements which are either greater then 0.35 or less than -0.35&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 15:47:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-flag-values-in-certain-range-s-only-flags-within/m-p/835206#M330184</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-09-26T15:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: Array to flag values in certain range(s) only flags within rounding error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-flag-values-in-certain-range-s-only-flags-within/m-p/835207#M330185</link>
      <description>&lt;P&gt;I'm making two lists:&amp;nbsp; one is a list of all the items (rows) that are &amp;gt;= .35 on at least one variable; the other is a list of items (rows) that are &amp;lt; .35 on all the variables.&amp;nbsp; Items (rows) with a highest value of&amp;nbsp; .346 on any variable end up on the list that is supposed to be &amp;gt;= .35.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 15:56:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-flag-values-in-certain-range-s-only-flags-within/m-p/835207#M330185</guid>
      <dc:creator>awesome_opossum</dc:creator>
      <dc:date>2022-09-26T15:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: Array to flag values in certain range(s) only flags within rounding error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-flag-values-in-certain-range-s-only-flags-within/m-p/835208#M330186</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/434421"&gt;@awesome_opossum&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi there, so I'm trying to use this little doo-wop to flag variables that have values within certain range(s) (&amp;gt;= |.35|):&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data flags (drop= i); set data; 
array factor {10} factor1-factor10; 
array place {10} place1-place10; 
do i = 1 to 10; 
	place{i} = 0; 
	if factor{i} &amp;lt; .35 and factor{i} &amp;gt; -.35 then place{i} = 1; /* &amp;gt;= |.35| threshold is somewhat arbitrary, 
																	may be changed */ 
end; 
noload_ct = sum(of place1-place10); 
noload = 0; 
if noload_ct = 10 then noload = 1; 
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now, I've done this before with other data, and it appeared to work as expected.&amp;nbsp; But in this particular instance, upon inspection of the values I'm trying to filter, it &lt;STRONG&gt;is&lt;/STRONG&gt; flagging cases that are &lt;SPAN&gt;&lt;EM&gt;≈&lt;/EM&gt;&lt;/SPAN&gt; .346, which are obviously are not &amp;gt;=|.35|.&amp;nbsp; Such "close" cases perhaps simply did not exist in prior use of this approach; hence I did not notice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suppose I can chalk this up to some sort of rounding that is going on behind the scenes.&amp;nbsp; For my present purposes, I imagine this is fine, but my concern is still that it would be technically inaccurate to say that I used a threshold of &amp;gt;= .35, when the output retains values that are technically, say, &amp;gt; .345 (or whatever it is that's happening behind the scenes).&amp;nbsp; That is, if someone replicated the analysis with the same data, they might observe this inconsistency, and say, awesome_opossum, &lt;EM&gt;"you're wrong, and a liar; how dare you."&lt;/EM&gt;, which is principally silly enough that it is something I wish to avoid.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone have an explanation for this, that I can at least include in a footnote (e.g. is it actually &amp;gt; .345 -- values rounded to the hundredth?), or any recommendations?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Check what you think you have written. 0.346 is indeed &amp;lt; 0.35 and&amp;nbsp; 0.346 &amp;gt; -0.35 as shown in your code. &lt;/P&gt;
&lt;P&gt;Or provide some example data in the form of a data step and what you expect for results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there some reason that you did not use the ABS function?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Abs(factor[i]) ge 0.35&lt;/PRE&gt;
&lt;P&gt;is the equivalent to test "&amp;gt;= |.35|".&lt;/P&gt;
&lt;P&gt;Or if you want the negation&lt;/P&gt;
&lt;PRE&gt;abs(factor[i]) lt 0.35&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Sep 2022 15:56:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-flag-values-in-certain-range-s-only-flags-within/m-p/835208#M330186</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-26T15:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: Array to flag values in certain range(s) only flags within rounding error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-flag-values-in-certain-range-s-only-flags-within/m-p/835209#M330187</link>
      <description>&lt;P&gt;Something else must be going on.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  do factor=.,0,.346,.36,1 ;
    *factor = round(factor,0.01);
    lt0_35 = factor &amp;lt; 0.35;
    ge0_35 = factor &amp;gt;= 0.35;
    output;
  end;
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    factor    lt0_35    ge0_35

 1       .          1         0
 2      0.000       1         0
 3      0.346       1         0
 4      0.360       0         1
 5      1.000       0         1

&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Sep 2022 15:57:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-flag-values-in-certain-range-s-only-flags-within/m-p/835209#M330187</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-26T15:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: Array to flag values in certain range(s) only flags within rounding error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-flag-values-in-certain-range-s-only-flags-within/m-p/835210#M330188</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data; 
  array factor {10} factor1-factor10 (.344 .345 .346 .347 .348 .349 .350 .351 .352 .353); 
run;


data flags (drop= i); 
  set data; 
  array factor {10} factor1-factor10; 
  array ge {10} (10*0); /* &amp;gt;= .35 */ 
  array ls {10} (10*0); /*  &amp;lt; .35 */


    do i = 1 to 10; 
    	ge{i} = (factor{i}  &amp;gt;= .35 );
      ls{i} = (factor{i}   &amp;lt; .35 );
    end;
  put (_ALL_) (=/);
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;255
256  data data;
257    array factor {10} factor1-factor10 (.344 .345 .346 .347 .348 .349 .350 .351 .352
257! .353);
258  run;

NOTE: The data set WORK.DATA has 1 observations and 10 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


259
260
261  data flags (drop= i);
262    set data;
263    array factor {10} factor1-factor10;
264    array ge {10} (10*0); /* &amp;gt;= .35 */
265    array ls {10} (10*0); /*  &amp;lt; .35 */
266
267
268      do i = 1 to 10;
269        ge{i} = (factor{i}  &amp;gt;= .35 );
270        ls{i} = (factor{i}   &amp;lt; .35 );
271      end;
272    put (_ALL_) (=/);
273  run;


factor1=0.344
factor2=0.345
factor3=0.346
factor4=0.347
factor5=0.348
factor6=0.349
factor7=0.35
factor8=0.351
factor9=0.352
factor10=0.353
ge1=0
ge2=0
ge3=0
ge4=0
ge5=0
ge6=0
ge7=1
ge8=1
ge9=1
ge10=1
ls1=1
ls2=1
ls3=1
ls4=1
ls5=1
ls6=1
ls7=0
ls8=0
ls9=0
ls10=0
i=11
NOTE: There were 1 observations read from the data set WORK.DATA.
NOTE: The data set WORK.FLAGS has 1 observations and 30 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Sep 2022 15:59:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-flag-values-in-certain-range-s-only-flags-within/m-p/835210#M330188</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-09-26T15:59:47Z</dc:date>
    </item>
    <item>
      <title>Re: Array to flag values in certain range(s) only flags within rounding error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-flag-values-in-certain-range-s-only-flags-within/m-p/835215#M330192</link>
      <description>The abs() function actually did solve the problem! Still strange my method didn't work; but elegant solution; I appreciate it!</description>
      <pubDate>Mon, 26 Sep 2022 16:20:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-flag-values-in-certain-range-s-only-flags-within/m-p/835215#M330192</guid>
      <dc:creator>awesome_opossum</dc:creator>
      <dc:date>2022-09-26T16:20:26Z</dc:date>
    </item>
  </channel>
</rss>

