<?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: Expanding a range of numbers in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Expanding-a-range-of-numbers/m-p/733051#M228431</link>
    <description>&lt;P&gt;First question, do your "range" values actually have quote marks as a SAS data value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the values actually contain the quote character:&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   if flag then do number = input(scan(range,1,"'-"),8.) to input(scan(range,2,"'-"),8.);
        output;
   end;
   else do;
      number=input (scan(range,1,"'-"),8.);
      output;
   end;
run;&lt;/PRE&gt;
&lt;P&gt;If not&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   if flag then do number = input(scan(range,1,"-"),8.) to input(scan(range,2,"-"),8.);
        output;
   end;
   else do;
      number=input (scan(range,1,"-"),8.);
      output;
   end;
run;&lt;/PRE&gt;
&lt;P&gt;Hard to see but there is a single quote inside the double quotes in the Scan function in the first version.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 12 Apr 2021 17:51:11 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-04-12T17:51:11Z</dc:date>
    <item>
      <title>Expanding a range of numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Expanding-a-range-of-numbers/m-p/733049#M228429</link>
      <description>&lt;P&gt;I have data that contains a range of numbers with a variable called flag for each range. It looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="632px"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="289px"&gt;range&lt;/TD&gt;
&lt;TD width="343px"&gt;flag&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="289px"&gt;'10040-10040'&lt;/TD&gt;
&lt;TD width="343px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="289px"&gt;'10060-10061'&lt;/TD&gt;
&lt;TD width="343px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to expand this to a dataset that looks like this.&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="289px" height="30px"&gt;number&lt;/TD&gt;
&lt;TD width="343px" height="30px"&gt;flag&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="289px" height="30px"&gt;10040&lt;/TD&gt;
&lt;TD width="343px" height="30px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="289px" height="30px"&gt;10060&lt;/TD&gt;
&lt;TD width="343px" height="30px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="289px" height="30px"&gt;10061&lt;/TD&gt;
&lt;TD width="343px" height="30px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's easy to define the beginning and end of the range but not sure exactly how to write the right do loop for this. I'd appreciate any advice.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Apr 2021 17:31:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Expanding-a-range-of-numbers/m-p/733049#M228429</guid>
      <dc:creator>chuakp</dc:creator>
      <dc:date>2021-04-12T17:31:30Z</dc:date>
    </item>
    <item>
      <title>Re: Expanding a range of numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Expanding-a-range-of-numbers/m-p/733051#M228431</link>
      <description>&lt;P&gt;First question, do your "range" values actually have quote marks as a SAS data value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the values actually contain the quote character:&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   if flag then do number = input(scan(range,1,"'-"),8.) to input(scan(range,2,"'-"),8.);
        output;
   end;
   else do;
      number=input (scan(range,1,"'-"),8.);
      output;
   end;
run;&lt;/PRE&gt;
&lt;P&gt;If not&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   if flag then do number = input(scan(range,1,"-"),8.) to input(scan(range,2,"-"),8.);
        output;
   end;
   else do;
      number=input (scan(range,1,"-"),8.);
      output;
   end;
run;&lt;/PRE&gt;
&lt;P&gt;Hard to see but there is a single quote inside the double quotes in the Scan function in the first version.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Apr 2021 17:51:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Expanding-a-range-of-numbers/m-p/733051#M228431</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-12T17:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: Expanding a range of numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Expanding-a-range-of-numbers/m-p/733052#M228432</link>
      <description>&lt;P&gt;The variable is a string in which the numbers are surrounded by quotes.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Apr 2021 17:50:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Expanding-a-range-of-numbers/m-p/733052#M228432</guid>
      <dc:creator>chuakp</dc:creator>
      <dc:date>2021-04-12T17:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: Expanding a range of numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Expanding-a-range-of-numbers/m-p/733055#M228434</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
LENGTH range $ 20;
input range	$ flag;
range_wo_quotes=compress(range,"'");
start_range=input(scan(range_wo_quotes,1,'-'),12.);
stop_range =input(scan(range_wo_quotes,2,'-'),12.);
cards;
'10040-10040'	0
'10060-10061'	1
;
run;
data want;
 set have;
  do number=start_range to stop_range;
  output;
 end;
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Apr 2021 17:54:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Expanding-a-range-of-numbers/m-p/733055#M228434</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-04-12T17:54:52Z</dc:date>
    </item>
    <item>
      <title>Re: Expanding a range of numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Expanding-a-range-of-numbers/m-p/733056#M228435</link>
      <description>This is pretty close to this question here:&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/I-need-to-turn-a-range-of-values-i-e-A0259-B3548-into-a-list-of/m-p/732672#M228323" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/I-need-to-turn-a-range-of-values-i-e-A0259-B3548-into-a-list-of/m-p/732672#M228323&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;The answer will also be very similar.</description>
      <pubDate>Mon, 12 Apr 2021 17:55:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Expanding-a-range-of-numbers/m-p/733056#M228435</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-12T17:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: Expanding a range of numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Expanding-a-range-of-numbers/m-p/733060#M228438</link>
      <description>&lt;P&gt;Thanks - this works, but could you help me understand the logic of this code - what does it mean for "if flag" to be true versus false?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if flag then do number = input(scan(range,1,"'-"),8.) to input(scan(range,2,"'-"),8.);&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Apr 2021 18:13:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Expanding-a-range-of-numbers/m-p/733060#M228438</guid>
      <dc:creator>chuakp</dc:creator>
      <dc:date>2021-04-12T18:13:13Z</dc:date>
    </item>
    <item>
      <title>Re: Expanding a range of numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Expanding-a-range-of-numbers/m-p/733061#M228439</link>
      <description>&lt;P&gt;Never mind, I answered my own question.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Apr 2021 18:16:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Expanding-a-range-of-numbers/m-p/733061#M228439</guid>
      <dc:creator>chuakp</dc:creator>
      <dc:date>2021-04-12T18:16:30Z</dc:date>
    </item>
    <item>
      <title>Re: Expanding a range of numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Expanding-a-range-of-numbers/m-p/733062#M228440</link>
      <description>&lt;P&gt;Thanks. This code works and is very helpful.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Apr 2021 18:17:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Expanding-a-range-of-numbers/m-p/733062#M228440</guid>
      <dc:creator>chuakp</dc:creator>
      <dc:date>2021-04-12T18:17:01Z</dc:date>
    </item>
    <item>
      <title>Re: Expanding a range of numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Expanding-a-range-of-numbers/m-p/733087#M228450</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/312"&gt;@chuakp&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Never mind, I answered my own question.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You might play around with SAS numeric values and the results of logic functions.&lt;/P&gt;
&lt;P&gt;In general SAS resolves any logic result to 1 for true and 0 for false:&amp;nbsp;&amp;nbsp;&amp;nbsp; If x=3 then&amp;nbsp; &amp;lt;do something&amp;gt;, for instance becomes If 1 then when x is indeed 3 or 0 otherwise. So when you have a 1/0 coded variable then IF Variable behaves that way as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Other numeric values will be treated as true. Exercise left to the interested reader.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Apr 2021 19:31:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Expanding-a-range-of-numbers/m-p/733087#M228450</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-12T19:31:40Z</dc:date>
    </item>
  </channel>
</rss>

