<?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 Separating string in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Separating-string/m-p/839170#M36327</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have variables with observations in different lengths as 000R201806,&amp;nbsp;ZY201906&lt;/P&gt;
&lt;P&gt;and I want to separate it into the letters (or digits) at the beginning of the string, the year, and the month:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;000R&amp;nbsp; &amp;nbsp; &amp;nbsp;2018&amp;nbsp; &amp;nbsp; 04&lt;/P&gt;
&lt;P&gt;ZY&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2019&amp;nbsp; &amp;nbsp; 06&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What code can I use?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;Lior&lt;/P&gt;</description>
    <pubDate>Tue, 18 Oct 2022 12:04:41 GMT</pubDate>
    <dc:creator>lioradam</dc:creator>
    <dc:date>2022-10-18T12:04:41Z</dc:date>
    <item>
      <title>Separating string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Separating-string/m-p/839170#M36327</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have variables with observations in different lengths as 000R201806,&amp;nbsp;ZY201906&lt;/P&gt;
&lt;P&gt;and I want to separate it into the letters (or digits) at the beginning of the string, the year, and the month:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;000R&amp;nbsp; &amp;nbsp; &amp;nbsp;2018&amp;nbsp; &amp;nbsp; 04&lt;/P&gt;
&lt;P&gt;ZY&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2019&amp;nbsp; &amp;nbsp; 06&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What code can I use?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;Lior&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2022 12:04:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Separating-string/m-p/839170#M36327</guid>
      <dc:creator>lioradam</dc:creator>
      <dc:date>2022-10-18T12:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: Separating string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Separating-string/m-p/839176#M36328</link>
      <description>&lt;P&gt;Always two digits for the month, four digits for the year, and the rest is the 'beginning of the string'?&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2022 12:13:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Separating-string/m-p/839176#M36328</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-10-18T12:13:16Z</dc:date>
    </item>
    <item>
      <title>Re: Separating string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Separating-string/m-p/839180#M36329</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/133482"&gt;@lioradam&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have variables with observations in different lengths as 000R201806,&amp;nbsp;ZY201906&lt;/P&gt;
&lt;P&gt;and I want to separate it into the letters (or digits) at the beginning of the string, the year, and the month:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;000R&amp;nbsp; &amp;nbsp; &amp;nbsp;2018&amp;nbsp; &amp;nbsp; 04&lt;/P&gt;
&lt;P&gt;ZY&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2019&amp;nbsp; &amp;nbsp; 06&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What code can I use?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;Lior&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;SUBSTR().&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that it might be simpler to just create a DATE value instead of separate YEAR and MONTH values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input string $20.;
cards;
000R201806
ZY201906
;

data want;
  set have;
  date = input(substrn(string,length(string)-5),yymmn6.);
  format date yymmdd10.;
  short_string=substr(string,1,length(string)-6);
  year=year(date);
  month=month(date);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;                                   short_
Obs      string            date    string    year    month

 1     000R201806    2018-06-01     000R     2018      6
 2     ZY201906      2019-06-01     ZY       2019      6
&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Oct 2022 12:15:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Separating-string/m-p/839180#M36329</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-10-18T12:15:00Z</dc:date>
    </item>
    <item>
      <title>Re: Separating string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Separating-string/m-p/839188#M36330</link>
      <description>&lt;P&gt;Yes&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2022 12:36:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Separating-string/m-p/839188#M36330</guid>
      <dc:creator>lioradam</dc:creator>
      <dc:date>2022-10-18T12:36:58Z</dc:date>
    </item>
    <item>
      <title>Re: Separating string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Separating-string/m-p/839190#M36331</link>
      <description>&lt;P&gt;Looks like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;beat me to it, but really you just need the length of the string, and then the last 6 characters are the year/month, and the rest are the "beginning of the string".&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2022 12:42:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Separating-string/m-p/839190#M36331</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-10-18T12:42:33Z</dc:date>
    </item>
    <item>
      <title>Re: Separating string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Separating-string/m-p/839266#M36344</link>
      <description>&lt;P&gt;Thank you very much!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Lior&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2022 19:20:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Separating-string/m-p/839266#M36344</guid>
      <dc:creator>lioradam</dc:creator>
      <dc:date>2022-10-18T19:20:34Z</dc:date>
    </item>
    <item>
      <title>Re: Separating string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Separating-string/m-p/839268#M36345</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2022 19:22:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Separating-string/m-p/839268#M36345</guid>
      <dc:creator>lioradam</dc:creator>
      <dc:date>2022-10-18T19:22:27Z</dc:date>
    </item>
  </channel>
</rss>

