<?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: subsetting data with a name range in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/subsetting-data-with-a-name-range/m-p/110543#M22919</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use array() to save some typing if you have many vars:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input x1-x3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;0 1 2&lt;/P&gt;&lt;P&gt;1 -2 3&lt;/P&gt;&lt;P&gt;3 4 5&lt;/P&gt;&lt;P&gt;-1 0 2&lt;/P&gt;&lt;P&gt;2 2 2&lt;/P&gt;&lt;P&gt;3 3 -3&amp;nbsp; &lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;array x x1-x3;&lt;/P&gt;&lt;P&gt;do over x;&lt;/P&gt;&lt;P&gt;if x&amp;lt;0 then output;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 10 May 2012 16:16:42 GMT</pubDate>
    <dc:creator>Haikuo</dc:creator>
    <dc:date>2012-05-10T16:16:42Z</dc:date>
    <item>
      <title>subsetting data with a name range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsetting-data-with-a-name-range/m-p/110542#M22918</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i want a way to check to see if any variables in my named range are negative. is there a more efficient way of accomplishing this ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; input&amp;nbsp;&amp;nbsp; (x1-x3) (2.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;0 1 2&lt;/P&gt;&lt;P&gt;1 -2 3&lt;/P&gt;&lt;P&gt;3 4 5&lt;/P&gt;&lt;P&gt;-1 0 2&lt;/P&gt;&lt;P&gt;2 2 2&lt;/P&gt;&lt;P&gt;3 3 -3&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if x1&amp;lt;0 or &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x2&amp;lt;0 or &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x3&amp;lt;0;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 16:12:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsetting-data-with-a-name-range/m-p/110542#M22918</guid>
      <dc:creator>SAShole</dc:creator>
      <dc:date>2012-05-10T16:12:13Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting data with a name range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsetting-data-with-a-name-range/m-p/110543#M22919</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use array() to save some typing if you have many vars:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input x1-x3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;0 1 2&lt;/P&gt;&lt;P&gt;1 -2 3&lt;/P&gt;&lt;P&gt;3 4 5&lt;/P&gt;&lt;P&gt;-1 0 2&lt;/P&gt;&lt;P&gt;2 2 2&lt;/P&gt;&lt;P&gt;3 3 -3&amp;nbsp; &lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;array x x1-x3;&lt;/P&gt;&lt;P&gt;do over x;&lt;/P&gt;&lt;P&gt;if x&amp;lt;0 then output;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 16:16:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsetting-data-with-a-name-range/m-p/110543#M22919</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-05-10T16:16:42Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting data with a name range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsetting-data-with-a-name-range/m-p/110544#M22920</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;actually if using variable list, you can just do this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;if min(of x1-x3)&amp;lt;0 then output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 16:19:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsetting-data-with-a-name-range/m-p/110544#M22920</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-05-10T16:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting data with a name range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsetting-data-with-a-name-range/m-p/110545#M22921</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Try this..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have2(drop=i);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; input&amp;nbsp;&amp;nbsp; (x1-x3) (2.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; array xx(3) x1-x3;&lt;/P&gt;&lt;P&gt;do i = 1 to dim(xx);&lt;/P&gt;&lt;P&gt;if xx(i)&amp;lt;0 then output;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;0 1 2&lt;/P&gt;&lt;P&gt;1 -2 3&lt;/P&gt;&lt;P&gt;3 4 5&lt;/P&gt;&lt;P&gt;-1 0 2&lt;/P&gt;&lt;P&gt;2 2 2&lt;/P&gt;&lt;P&gt;3 3 -3&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Shiva&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 16:20:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsetting-data-with-a-name-range/m-p/110545#M22921</guid>
      <dc:creator>shivas</dc:creator>
      <dc:date>2012-05-10T16:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting data with a name range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsetting-data-with-a-name-range/m-p/110546#M22922</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you're outputting the whole row then check if the min is less than 0.&lt;/P&gt;&lt;P&gt;However this does require you to list your variables whereas in the array method you don't.&lt;/P&gt;&lt;P&gt;The where will process faster though. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;where min(x1, x2, x3) &amp;lt;0;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 16:21:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsetting-data-with-a-name-range/m-p/110546#M22922</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2012-05-10T16:21:29Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting data with a name range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsetting-data-with-a-name-range/m-p/110547#M22923</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is likely to run faster if you switch from an IF to a WHERE statement.&amp;nbsp; (Whether you can notice the difference depends on characteristics of your data such as how many observations you are selecting, and how wide the observations are.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you know which variable(s) are most likely to be negative, you could switch the order around.&amp;nbsp; For example if X3 is usually the culprit, mention it first:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where x3 &amp;lt; 0 or x1 &amp;lt; 0 or x2 &amp;lt; 0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Finally, notice that this code also selects missing values, not just negative numbers.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All of this is dependent on what you mean by "more efficient".&amp;nbsp; I've interpreted it to mean you want something that would run faster, but that's not the only possible definition.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 16:25:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsetting-data-with-a-name-range/m-p/110547#M22923</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-05-10T16:25:58Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting data with a name range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsetting-data-with-a-name-range/m-p/110548#M22924</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Astounding , as he/she always, just raised valid point on dealing with missing value. So just add: if .&amp;lt;min(of x1-x3)&amp;lt;0 then;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, from my own experience, it is NOT always that 'where' is faster then 'if'. If you are dealing with a big data set with more than half of the obs meeting condition, 'if' could be significant faster than 'where'. I have noticed this in numerous counts in my work. That being said, direct access is not always faster than 'sequential access'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just my 2 cents,&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 16:36:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsetting-data-with-a-name-range/m-p/110548#M22924</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-05-10T16:36:25Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting data with a name range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsetting-data-with-a-name-range/m-p/110549#M22925</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can't use the OF in a WHERE statement, but you can in the IF statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 16:45:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsetting-data-with-a-name-range/m-p/110549#M22925</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2012-05-10T16:45:49Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting data with a name range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsetting-data-with-a-name-range/m-p/110550#M22926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks everybody for your input!&lt;/P&gt;&lt;P&gt;@Astounding, I should have said by efficient i mean not having to explicitly type out all vars between var1 &amp;amp; varX. in reality my data set has a named range with 100 fields.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 17:16:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsetting-data-with-a-name-range/m-p/110550#M22926</guid>
      <dc:creator>SAShole</dc:creator>
      <dc:date>2012-05-10T17:16:46Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting data with a name range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsetting-data-with-a-name-range/m-p/110551#M22927</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Didn't know that! Thanks! Right now, I mostly use 'where' in procs and index,&amp;nbsp; where you can't use 'if' or 'if' does not utilize index.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 17:24:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsetting-data-with-a-name-range/m-p/110551#M22927</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-05-10T17:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting data with a name range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsetting-data-with-a-name-range/m-p/110552#M22928</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi ... since MIN ignores missing values (unless all are missing), I don't think that you have to do this ... &lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG style="background-color: #ffffff;"&gt; if .&amp;lt;min(of x1-x3)&amp;lt;0 &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;to cover situations when all are missing, you could try just adding a non-negative value to the function arguments ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;data have;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;input x1-x3 @@;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;cards;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;. 1 2&amp;nbsp;&amp;nbsp; 1 -2 3&amp;nbsp;&amp;nbsp; 3 4 .&amp;nbsp;&amp;nbsp; -1 0 2&amp;nbsp;&amp;nbsp; 2 2 2&amp;nbsp;&amp;nbsp; 3 3 -3&amp;nbsp;&amp;nbsp; . . .&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;data negative;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;set have;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;if min(of x:, 0) lt 0;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;x1&amp;nbsp;&amp;nbsp;&amp;nbsp; x2&amp;nbsp;&amp;nbsp;&amp;nbsp; x3&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; -2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;-1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp; -3&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 12 May 2012 21:15:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsetting-data-with-a-name-range/m-p/110552#M22928</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2012-05-12T21:15:55Z</dc:date>
    </item>
  </channel>
</rss>

