<?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: Extract number sequence from string in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Extract-number-sequence-from-string/m-p/682405#M24107</link>
    <description>Sure I forgot to specify this point. The variable after transformation shall remain character.</description>
    <pubDate>Tue, 08 Sep 2020 20:02:55 GMT</pubDate>
    <dc:creator>Matos</dc:creator>
    <dc:date>2020-09-08T20:02:55Z</dc:date>
    <item>
      <title>Extract number sequence from string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-number-sequence-from-string/m-p/682386#M24104</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;I have a data set which contains a string variable specifying ranges of values. Some rows display the first and the last value of the range while others display a list of all possible values from the range, separated by a comma, like this:&lt;/P&gt;
&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="lia-align-left"&gt;&lt;STRONG&gt;Data have:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="112"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="112" class="lia-align-center"&gt;&lt;STRONG&gt;Var1&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;010-0100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;020-050&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;010,025,048,061&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Line by line, I would need to extract all possible values from the range to a different column, such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Data want:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 48pt;" border="0" width="64" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl65" style="height: 15.0pt; width: 48pt;"&gt;&lt;STRONG&gt;Var1&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt;"&gt;010&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt;"&gt;020&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt;"&gt;030&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt;"&gt;040&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt;"&gt;050&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt;"&gt;060&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt;"&gt;070&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt;"&gt;080&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt;"&gt;090&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt;"&gt;0100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl67" style="height: 15.0pt;"&gt;020&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl67" style="height: 15.0pt;"&gt;030&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl67" style="height: 15.0pt;"&gt;040&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl67" style="height: 15.0pt;"&gt;050&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl68" style="height: 15.0pt;"&gt;010&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl68" style="height: 15.0pt;"&gt;025&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl68" style="height: 15.0pt;"&gt;048&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl68" style="height: 15.0pt;"&gt;061&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For ranges delimited by "-" the sequence increments always with a step of +10, e.g.: 010, 020, 030...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can this transformation be achieved in SAS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2020 19:42:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-number-sequence-from-string/m-p/682386#M24104</guid>
      <dc:creator>Matos</dc:creator>
      <dc:date>2020-09-08T19:42:00Z</dc:date>
    </item>
    <item>
      <title>Re: Extract number sequence from string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-number-sequence-from-string/m-p/682392#M24105</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/247128"&gt;@Matos&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;I have a data set which contains a string variable specifying ranges of values. Some rows display the first and the last value of the range while others display a list of all possible values from the range, separated by a comma, like this:&lt;/P&gt;
&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="lia-align-left"&gt;&lt;STRONG&gt;Data have:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="112"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="112" class="lia-align-center"&gt;&lt;STRONG&gt;Var1&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;010-0100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;020-050&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;010,025,048,061&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Line by line, I would need to extract all possible values from the range to a different column, such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Data want:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 48pt;" border="0" width="64" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl65" style="height: 15.0pt; width: 48pt;"&gt;&lt;STRONG&gt;Var1&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt;"&gt;010&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt;"&gt;020&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt;"&gt;030&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt;"&gt;040&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt;"&gt;050&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt;"&gt;060&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt;"&gt;070&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt;"&gt;080&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt;"&gt;090&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt;"&gt;0100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl67" style="height: 15.0pt;"&gt;020&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl67" style="height: 15.0pt;"&gt;030&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl67" style="height: 15.0pt;"&gt;040&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl67" style="height: 15.0pt;"&gt;050&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl68" style="height: 15.0pt;"&gt;010&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl68" style="height: 15.0pt;"&gt;025&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl68" style="height: 15.0pt;"&gt;048&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl68" style="height: 15.0pt;"&gt;061&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For ranges delimited by "-" the sequence increments always with a step of +10, e.g.: 010, 020, 030...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can this transformation be achieved in SAS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes but you need to answer a few questions to clarify what you actually want.&lt;/P&gt;
&lt;P&gt;Are you wanting to create actual numeric values or character values?&lt;/P&gt;
&lt;P&gt;Once your variable Var1 is created as character it will stay as such and numeric values would have be another variable.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2020 19:48:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-number-sequence-from-string/m-p/682392#M24105</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-08T19:48:04Z</dc:date>
    </item>
    <item>
      <title>Re: Extract number sequence from string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-number-sequence-from-string/m-p/682405#M24107</link>
      <description>Sure I forgot to specify this point. The variable after transformation shall remain character.</description>
      <pubDate>Tue, 08 Sep 2020 20:02:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-number-sequence-from-string/m-p/682405#M24107</guid>
      <dc:creator>Matos</dc:creator>
      <dc:date>2020-09-08T20:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: Extract number sequence from string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-number-sequence-from-string/m-p/682419#M24109</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/247128"&gt;@Matos&lt;/a&gt;&amp;nbsp; Is this what you're looking for?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    input var1 &amp;amp; $100.;
    datalines;
    010-0100  
    020-050  
    010,025,048,061  
    ;
run;

data want (keep=var2);
    set have;
    if find(var1, '-') &amp;gt; 1
        then do;
            range_start = substr(var1, 1, find(var1,'-') - 1);
            range_end = substr(var1, find(var1,'-') + 1);
            increment = input(range_start, best8.) + 10;

            var2 = range_start;
            output;

            do while (increment &amp;lt; range_end);
                var2 = put(increment, z3.);
                output;
                increment + 10;
            end;

            var2 = range_end;
            output;
        end;
    else if find(var1, ',')
        then do;
            do i=1 to countw(var1,',');
               var2 = scan(var1,i,',');
               output;
            end;
        end;
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mklangley_0-1599600426427.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49139i1A95495B171533C9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mklangley_0-1599600426427.png" alt="mklangley_0-1599600426427.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2020 21:27:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-number-sequence-from-string/m-p/682419#M24109</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2020-09-08T21:27:35Z</dc:date>
    </item>
    <item>
      <title>Re: Extract number sequence from string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-number-sequence-from-string/m-p/682528#M24115</link>
      <description>&lt;P&gt;Absolutely! Thanks a lot for your help mklangley.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2020 07:18:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-number-sequence-from-string/m-p/682528#M24115</guid>
      <dc:creator>Matos</dc:creator>
      <dc:date>2020-09-09T07:18:37Z</dc:date>
    </item>
  </channel>
</rss>

