<?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: substr function question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/substr-function-question/m-p/440322#M109960</link>
    <description>&lt;P&gt;Thank you all for your quick answers and usefull tips!!!!&lt;/P&gt;</description>
    <pubDate>Mon, 26 Feb 2018 20:00:52 GMT</pubDate>
    <dc:creator>sabuni</dc:creator>
    <dc:date>2018-02-26T20:00:52Z</dc:date>
    <item>
      <title>substr function question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substr-function-question/m-p/438489#M109339</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To whom it may concern,&lt;/P&gt;&lt;P&gt;I have an issue, I must extract only part of a string variable. The string variable is very diverse (ie below).&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;‘ORGINAL’ String variable&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;‘TO BE’ New string variable&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;BESLAGNR: 31099488&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;BE31099488-0101&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;BESLAGNR: 310-00147&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;BE31000147-0101&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;BESLAGNR: 10012390 - LANGE METHODE!&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;BE10012390-0101&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I found your address on a tuto on, the internet. Would you be able to help me with the current issue?&lt;/P&gt;&lt;P&gt;Thanking you in advance,&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Sarah&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2018 20:49:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substr-function-question/m-p/438489#M109339</guid>
      <dc:creator>sabuni</dc:creator>
      <dc:date>2018-02-19T20:49:05Z</dc:date>
    </item>
    <item>
      <title>Re: substr function question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substr-function-question/m-p/438498#M109344</link>
      <description>&lt;P&gt;In this situation you're going to need more than just the SUBSTR() function. Here's some sample code I wrote to mock up your scenario that gives the results you asked for:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	length original $ 50;
	infile datalines DLM=",";
	input original $;
	number = SCAN(original, 2, " ");
	myString = CATS("BE", COMPRESS(number, "-"), "-0101");

datalines;
BESLAGNR: 31099488
BESLAGNR: 310-00147
BESLAGNR: 10012390 - LANGE METHODE!
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Feb 2018 21:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substr-function-question/m-p/438498#M109344</guid>
      <dc:creator>GinaRepole</dc:creator>
      <dc:date>2018-02-19T21:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: substr function question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substr-function-question/m-p/438499#M109345</link>
      <description>&lt;P&gt;It depends on how much you know about the incoming values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you always want "BE" a the beginning, or does it depend on the incoming string?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you always want "-0101" at the end?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does the middle portion always contain all the numbers from the incoming string, or could there be numbers at the end of it that you want to ignore?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one possibility:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;new = substr(old, 1, 2) || compress(old, , 'kd') || '-0101';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2018 21:19:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substr-function-question/m-p/438499#M109345</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-19T21:19:37Z</dc:date>
    </item>
    <item>
      <title>Re: substr function question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substr-function-question/m-p/438561#M109361</link>
      <description>&lt;P&gt;Assuming that you want to have the first two letters of the old variable in the beginning, then the number part, with dashes removed, then '-0101', this may work:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
      length original $ 50;
      infile datalines DLM=",";
      input original $;
datalines;
BESLAGNR: 31099488
BESLAGNR: 310-00147
BESLAGNR: 10012390 - LANGE METHODE!
;

data want;
  set have;
  retain NewVar '          -0101';
  substr(NewVar,1,2)=Original;
  substr(NewVar,3,8)=compress(scan(Original,2,' '),'-');
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In other words, the substring function is also very useful when assigning to part of a variable.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2018 08:39:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substr-function-question/m-p/438561#M109361</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-02-20T08:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: substr function question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substr-function-question/m-p/440322#M109960</link>
      <description>&lt;P&gt;Thank you all for your quick answers and usefull tips!!!!&lt;/P&gt;</description>
      <pubDate>Mon, 26 Feb 2018 20:00:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substr-function-question/m-p/440322#M109960</guid>
      <dc:creator>sabuni</dc:creator>
      <dc:date>2018-02-26T20:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: substr function question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substr-function-question/m-p/440323#M109961</link>
      <description>&lt;P&gt;Thanks for info, very usefull!!!!&lt;/P&gt;</description>
      <pubDate>Mon, 26 Feb 2018 20:01:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substr-function-question/m-p/440323#M109961</guid>
      <dc:creator>sabuni</dc:creator>
      <dc:date>2018-02-26T20:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: substr function question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substr-function-question/m-p/440325#M109962</link>
      <description>&lt;P&gt;All these are very usefull tips, thanks a lot for quick answer!&lt;/P&gt;</description>
      <pubDate>Mon, 26 Feb 2018 20:03:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substr-function-question/m-p/440325#M109962</guid>
      <dc:creator>sabuni</dc:creator>
      <dc:date>2018-02-26T20:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: substr function question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substr-function-question/m-p/440354#M109973</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this code if the string is not in specific pattern to use SUBSTR to extract numbers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
      length original $ 50;
      infile datalines DLM=",";
      input original $;
datalines;
BESLAGNR: 31099488
BESLAGNR: 310-00147
BESLAGNR: 10012390 - LANGE METHODE!
;
RUN;
data want;
  set have;
Str=COMPRESS(CAT(SUBSTR(Original,1,2),compress(original,compress(original," ",'nt'),'iat'),'-0101'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Feb 2018 21:55:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substr-function-question/m-p/440354#M109973</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-02-26T21:55:12Z</dc:date>
    </item>
  </channel>
</rss>

