<?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 Substr variable of different lengths? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Substr-variable-of-different-lengths/m-p/415014#M67550</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi, I'm looking to create a substr of a variable that is of an uncertain length. The character variable I'm looking at in particular always starts with a number followed by a category, BUT the number and categories vary in length etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample data below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample;
input var1 $;
datalines;
1a
11b
12b(i)
12b(ii)
12c(iii)
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And what I want to end up with is as below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input var1 $ number $ category $;
datalines;
1a 1 a
11b 11 b
12b(i) 12 b(i)
12b(ii) 12 b(ii)
12c(iii) 12 c(iii)
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How can I go about doing a substr here? Or is there a different SAS function I can use?&lt;/P&gt;</description>
    <pubDate>Tue, 21 Nov 2017 03:42:01 GMT</pubDate>
    <dc:creator>Ltwo</dc:creator>
    <dc:date>2017-11-21T03:42:01Z</dc:date>
    <item>
      <title>Substr variable of different lengths?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Substr-variable-of-different-lengths/m-p/415014#M67550</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi, I'm looking to create a substr of a variable that is of an uncertain length. The character variable I'm looking at in particular always starts with a number followed by a category, BUT the number and categories vary in length etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample data below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample;
input var1 $;
datalines;
1a
11b
12b(i)
12b(ii)
12c(iii)
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And what I want to end up with is as below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input var1 $ number $ category $;
datalines;
1a 1 a
11b 11 b
12b(i) 12 b(i)
12b(ii) 12 b(ii)
12c(iii) 12 c(iii)
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How can I go about doing a substr here? Or is there a different SAS function I can use?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2017 03:42:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Substr-variable-of-different-lengths/m-p/415014#M67550</guid>
      <dc:creator>Ltwo</dc:creator>
      <dc:date>2017-11-21T03:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: Substr variable of different lengths?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Substr-variable-of-different-lengths/m-p/415252#M67558</link>
      <description>&lt;P&gt;In this case you might have better luck with the COMPRESS function. If you're not familiar with it, I strongly urge you to read the SAS documentation on it - it's quite a powerful function, which can allow you to keep or drop certain characters or types of characters (e.g. alphabetic characters, numbers). This step below will create what you need for this sample.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set sample;
    number = compress(var1,,'dk');
    category=compress(var1,,'d');
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2017 17:00:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Substr-variable-of-different-lengths/m-p/415252#M67558</guid>
      <dc:creator>bstarr</dc:creator>
      <dc:date>2017-11-21T17:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: Substr variable of different lengths?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Substr-variable-of-different-lengths/m-p/415260#M67559</link>
      <description>&lt;P&gt;You might try using the perl regular expression functions, if you already know them.&lt;/P&gt;
&lt;P&gt;But it is pretty easy to do with SUBSTR() and VERIFY() functions.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set sample;
  length number suffix $20;
  number=substrn(var1,1,verify(trim(var1),'1234567890')-1);
  suffix=substrn(var1,lengthn(number)+1);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 245px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16776i91634939F251846C/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2017 17:36:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Substr-variable-of-different-lengths/m-p/415260#M67559</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-21T17:36:41Z</dc:date>
    </item>
  </channel>
</rss>

