<?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: How to set condition within a range of numbers shortly in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-set-condition-within-a-range-of-numbers-shortly/m-p/722803#M224183</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there anyway to convert this code from "&lt;STRONG&gt;where&lt;/STRONG&gt;" to "&lt;STRONG&gt;if&lt;/STRONG&gt;" please ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TIA.&lt;/P&gt;</description>
    <pubDate>Tue, 02 Mar 2021 08:16:26 GMT</pubDate>
    <dc:creator>ResoluteCarbon</dc:creator>
    <dc:date>2021-03-02T08:16:26Z</dc:date>
    <item>
      <title>How to set condition within a range of numbers shortly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-set-condition-within-a-range-of-numbers-shortly/m-p/722791#M224174</link>
      <description>&lt;P&gt;Hi all!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my dataset, I have a data column named "SIC", it is a char variable&lt;/P&gt;&lt;P&gt;A small example&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SIC
3559
3559
3559
3559
4911
4911
4911
2070
2070
2070&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And I need to exclude observation that ( 4900&amp;lt;SIC&amp;lt;4949) and (6000&amp;lt;SIC&amp;lt;6999)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
     set have;&lt;BR /&gt;         SIC_ =input (SIC,8.);
         if SIC_&amp;lt;4900 or (4949&amp;lt;SIC_  and SIC_ &amp;lt; 6000) or (SIC_&amp;gt;6999) 
run&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;1. Can you tell me whether my datatype conversion as above is reasonable, I do not know when I should put 4. or 8. or 12., I have a look on this document but it is quite overwhelming to me&lt;/P&gt;&lt;P&gt;(&lt;A href="https://go.documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=allprodslang&amp;amp;docsetTarget=syntaxByType-format.htm&amp;amp;locale=en"&gt;https://go.documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=allprodslang&amp;amp;docsetTarget=syntaxByType-format.htm&amp;amp;locale=en&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. And is there any alternative way to code the condition above?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if SIC_&amp;lt;4900 or (4949&amp;lt;SIC_  and SIC_ &amp;lt; 6000) or (SIC_&amp;gt;6999)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 06:54:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-set-condition-within-a-range-of-numbers-shortly/m-p/722791#M224174</guid>
      <dc:creator>ResoluteCarbon</dc:creator>
      <dc:date>2021-03-02T06:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to set condition within a range of numbers shortly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-set-condition-within-a-range-of-numbers-shortly/m-p/722795#M224176</link>
      <description>&lt;P&gt;1) The 4., 8., or 12. is the informat. Meaning how SAS should read the variable. In this case, if you know you have only 4 digits, the right thing is to use 4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) If you don't really need the numeric value of SIC, you can use its converted value directly and do something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input SIC $;
datalines;
3559
3559
3559
3559
4911
4911
4911
2070
2070
2070
;

data want;
   set have;
   if input(sic, 4.) not in (4900:4949, 6000:6999);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Mar 2021 07:08:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-set-condition-within-a-range-of-numbers-shortly/m-p/722795#M224176</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-03-02T07:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to set condition within a range of numbers shortly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-set-condition-within-a-range-of-numbers-shortly/m-p/722797#M224177</link>
      <description>&lt;P&gt;You don't really need to convert data types:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data want;
   set have;
   where not (length(sic)=4 
              and
              (('4900'&amp;lt;sic&amp;lt;'4949') or ('6000'&amp;lt;sic&amp;lt;'6999'))
             );
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The "length(sic)=4" condition prevents a value like "493" (left justified) from qualifying as being between "4900" and "4949".&amp;nbsp; This is what would happen when lexicographic ordering is being applied.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 07:19:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-set-condition-within-a-range-of-numbers-shortly/m-p/722797#M224177</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-03-02T07:19:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to set condition within a range of numbers shortly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-set-condition-within-a-range-of-numbers-shortly/m-p/722803#M224183</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there anyway to convert this code from "&lt;STRONG&gt;where&lt;/STRONG&gt;" to "&lt;STRONG&gt;if&lt;/STRONG&gt;" please ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TIA.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 08:16:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-set-condition-within-a-range-of-numbers-shortly/m-p/722803#M224183</guid>
      <dc:creator>ResoluteCarbon</dc:creator>
      <dc:date>2021-03-02T08:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to set condition within a range of numbers shortly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-set-condition-within-a-range-of-numbers-shortly/m-p/722819#M224190</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/366546"&gt;@ResoluteCarbon&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there anyway to convert this code from "&lt;STRONG&gt;where&lt;/STRONG&gt;" to "&lt;STRONG&gt;if&lt;/STRONG&gt;" please ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TIA.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Context? Why is "IF" preferred over "WHERE"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you try replacing "where" with "if"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Where" is typically faster as it applies to the data vector as it is read into the data set and "If" is applied later.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 09:12:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-set-condition-within-a-range-of-numbers-shortly/m-p/722819#M224190</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-02T09:12:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to set condition within a range of numbers shortly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-set-condition-within-a-range-of-numbers-shortly/m-p/722872#M224217</link>
      <description>&lt;P&gt;Have you cleaned the data?&amp;nbsp; Values like those below could throw off your calculations:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;0000&lt;/P&gt;
&lt;P&gt;493A&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 15:08:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-set-condition-within-a-range-of-numbers-shortly/m-p/722872#M224217</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-03-02T15:08:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to set condition within a range of numbers shortly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-set-condition-within-a-range-of-numbers-shortly/m-p/722878#M224222</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/366546"&gt;@ResoluteCarbon&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there anyway to convert this code from "&lt;STRONG&gt;where&lt;/STRONG&gt;" to "&lt;STRONG&gt;if&lt;/STRONG&gt;" please ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TIA.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes ...&amp;nbsp;replace the word "where" with the word "if".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But, as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp; said, where is likely faster.&amp;nbsp; That's because the where filter is outsourced to the data engine, and the data step never sees the rejected data.&amp;nbsp; But the subsetting IF is not applied until after the data is read in.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 15:26:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-set-condition-within-a-range-of-numbers-shortly/m-p/722878#M224222</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-03-02T15:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to set condition within a range of numbers shortly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-set-condition-within-a-range-of-numbers-shortly/m-p/722957#M224267</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, you mean, in this specific case, where and if can be used interchangeable ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TIA.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 19:41:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-set-condition-within-a-range-of-numbers-shortly/m-p/722957#M224267</guid>
      <dc:creator>ResoluteCarbon</dc:creator>
      <dc:date>2021-03-02T19:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to set condition within a range of numbers shortly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-set-condition-within-a-range-of-numbers-shortly/m-p/722958#M224268</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is very nice to see your caution.&lt;/P&gt;&lt;P&gt;Can I ask why I need to filter "0000" value?&lt;/P&gt;&lt;P&gt;And I am quite confident about that "&lt;SPAN&gt;493A" will not exist following some finance papers. SIC is a 4-digit code as described from the datasource.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 19:43:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-set-condition-within-a-range-of-numbers-shortly/m-p/722958#M224268</guid>
      <dc:creator>ResoluteCarbon</dc:creator>
      <dc:date>2021-03-02T19:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to set condition within a range of numbers shortly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-set-condition-within-a-range-of-numbers-shortly/m-p/723052#M224315</link>
      <description>&lt;P&gt;"0000" would be selected, as it satisfies the condition SIC_ &amp;lt; 4900.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not sure if you want it to be selected or not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Missing values would also be selected, as they also satisfy that same condition.&amp;nbsp; (But they would be removed by checking for length of 4.)&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 00:45:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-set-condition-within-a-range-of-numbers-shortly/m-p/723052#M224315</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-03-03T00:45:48Z</dc:date>
    </item>
  </channel>
</rss>

