{"id":408,"date":"2014-07-18T15:15:46","date_gmt":"2014-07-18T15:15:46","guid":{"rendered":"http:\/\/www.spss-tutorials.com\/?p=408"},"modified":"2021-09-02T15:56:09","modified_gmt":"2021-09-02T13:56:09","slug":"spss-range-function","status":"publish","type":"post","link":"https:\/\/www.spss-tutorials.com\/spss-range-function\/","title":{"rendered":"SPSS RANGE Function &#8211; Quick Tutorial"},"content":{"rendered":"<!--body-->\n\n\n<p>\n<span class='code'>COMPUTE v2 = RANGE(V1,2,4).<\/span>\n<\/p>\n\n<span class='img w480'>\n\t<img src='https:\/\/spss-tutorials.com\/img\/spss-range-function.png' alt='SPSS Range Function Result' title='SPSS Range Function Result'>\n\t<span class='small'>SPSS RANGE Function Result<\/span>\n<\/span>\n\n<h2>Summary<\/h2>\n\n<p><a href=\"https:\/\/www.spss-tutorials.com\/spss-what-is-it\/\">SPSS<\/a>&rsquo; <code>RANGE<\/code> function is used to evaluate whether or not values are within a given range. Test values <em>equal to<\/em> the lower or upper boundary are also within the given range. Run the <a href=\"https:\/\/www.spss-tutorials.com\/spss-syntax\/ \">syntax<\/a> below for a quick demonstration.\n<\/p>\n\n<h2>SPSS Range Syntax Example<\/h2>\n\n<div class='code'><strong>*1. Create couple of cases.<br \/><\/strong><br \/>data list free\/v1(f1).<br \/>begin data<br \/>1 2 3 4 5 6<br \/>end data.<br \/><br \/><strong>*2. Check whether value on v2 is between 2 and 4.<br \/><\/strong><br \/>compute v2 = range(v1,2,4).<br \/>exe.<\/div><!--class='code'-->\n<h2>Notes<\/h2>\n\n<p><code>RANGE<\/code> takes three arguments. So in <code>RANGE(A,B,C)<\/code><\/p>\n\n<ul>\n\t<li><code>A<\/code> refers to the test value;<\/li>\n\t<li><code>B<\/code> refers to the lower boundary;<\/li>\n\t<li><code>C<\/code> refers to the upper boundary;<\/li>\n\t<li><code>A<\/code>, <code>B<\/code> and <code>C<\/code> can all be values within variables or constants (over cases). The most common scenario, however, is that <code>A<\/code> is a variable and <code>B<\/code> and <code>C<\/code> constants.<\/li>\n<\/ul>\n\n<p><code>RANGE<\/code> may return three values:<\/p>\n\n<ul>\n\t<li><strong>1<\/strong> (or &ldquo;True&rdquo;) if the test value is within the range;<\/li>\n\t<li><strong>0<\/strong> (or &ldquo;False&rdquo;) if the test value is not within the range;<\/li>\n\t<li>A <a href=\"https:\/\/www.spss-tutorials.com\/spss-missing-values-tutorial\/#sysmis\">system missing value<\/a><strong><\/strong> if the range can't be evaluated due to <a href=\"https:\/\/www.spss-tutorials.com\/spss-missing-values\/ \">missing values<\/a>.<\/li>\n<\/ul>\n\n<h2 id='times'>SPSS Range with Dates and Times<\/h2>\n\n<p>SPSS <code>RANGE<\/code> can be readily used with <a href=\"https:\/\/www.spss-tutorials.com\/spss-date-variables-tutorial\/\">date variables<\/a> and <a href=\"https:\/\/www.spss-tutorials.com\/spss-time-variables-basics\/ \">time variables<\/a>. It should be kept in mind that SPSS dates and times are expressed in numbers of seconds. This implies that you should convert &ldquo;normal&rdquo; date and time values into numbers of seconds too. This can be done with the <code>DATE.DMY<\/code> and <code>TIME.HMS<\/code> functions as shown in the syntax below.<span class='inline-comment'>Minutes and seconds default to zero in <code>TIME.HMS<\/code>. That is, <code>TIME.HMS(18,0,0)<\/code> may be shortened to <code>TIME.HMS(18)<\/code>.<\/span><\/p>\n\n<h2>SPSS Range Syntax Example<\/h2>\n\n<div class='code'><strong>*1. Create arrival time dataset.<br \/><\/strong><br \/>data list free\/arrival(time10).<br \/>begin data<br \/>10:32:12 12:59:43 16:34:36 17:20:50 18:41:23 23:48:03<br \/>end data.<br \/><br \/><strong>*2. Flag arrivals between noon and 6 PM.<br \/><\/strong><br \/>compute arrival_during_afternoon = range(arrival,time.hms(12,0,0),time.hms(18)).<br \/>exe.<\/div><!--class='code'-->\n<h2 id='strings'>SPSS Range with Strings<\/h2>\n\n<p>Technically, you can use <code>RANGE<\/code> for <a href=\"https:\/\/www.spss-tutorials.com\/spss-string-variables-basics\/ \">string<\/a> values too. SPSS basically uses an <a href='http:\/\/en.wikipedia.org\/wiki\/Alphabetical_order'>alphabetical order<\/a> to determine whether string values are in a given range or not. This can be seen by running <code>SORT CASES<\/code> as in the syntax example below.<\/p>\n\n<h2>SPSS Range Syntax Example<\/h2>\n\n<div class='code'><strong>*1. Create mini dataset.<br \/><\/strong><br \/>data list free\/v1(a2). <br \/>begin data <br \/>a b c C cc d D EE e f<br \/>end data. <br \/> <br \/><strong>*2. Sort cases.<br \/><\/strong><br \/>sort cases by v1.<br \/><br \/><strong>*3. Flag values between &#39;C&#39; and &#39;e&#39;.<br \/><\/strong><br \/>compute v2 = range(v1,&#39;C&#39;,&#39;e&#39;).<br \/>exe.<\/div><!--class='code'-->\n\n\n","protected":false},"excerpt":{"rendered":"<p>The SPSS RANGE function is used to evaluate whether or not values are within a given range. Test values equal to the lower or upper boundary are also within the given range.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[262],"tags":[],"class_list":["post-408","post","type-post","status-publish","format-standard","hentry","category-rr"],"_links":{"self":[{"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/posts\/408","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/comments?post=408"}],"version-history":[{"count":0,"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/posts\/408\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/media?parent=408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/categories?post=408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/tags?post=408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}