<?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: Using Substr function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-Substr-function/m-p/592734#M169975</link>
    <description>Use SCAN() since you have a clear delimiter. &lt;BR /&gt;&lt;BR /&gt;Code = scan(_name_, 2, "_");&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Mon, 30 Sep 2019 15:58:52 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-09-30T15:58:52Z</dc:date>
    <item>
      <title>Using Substr function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Substr-function/m-p/592729#M169972</link>
      <description>&lt;P&gt;I am trying to create the variable year as below from _Name_. Below is the code. Any help, comes out incorrect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data longMLS2;&lt;BR /&gt;set longMLS2 ;&lt;BR /&gt;year=input(substr(_NAME_, 4), 3.);&lt;BR /&gt;drop _name_;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 240pt;" border="0" width="320" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD width="64" height="21" style="height: 15.75pt; width: 48pt;"&gt;obs&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;caseid&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;_Name_&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;BMI&lt;/TD&gt;
&lt;TD width="64" class="xl67" style="width: 48pt;"&gt;&lt;STRONG&gt;Year&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl64" style="height: 15.0pt; width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl65" style="width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="width: 48pt;"&gt;BMI_Y2&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="width: 48pt;"&gt;.&lt;/TD&gt;
&lt;TD align="right" class="xl67"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl66" style="height: 15.0pt; width: 48pt;"&gt;2&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;BMI_Y3&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;.&lt;/TD&gt;
&lt;TD align="right" class="xl67"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl66" style="height: 15.0pt; width: 48pt;"&gt;3&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;BMI_Y4&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;.&lt;/TD&gt;
&lt;TD align="right" class="xl67"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl66" style="height: 15.0pt; width: 48pt;"&gt;4&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;BMI_Y5&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;.&lt;/TD&gt;
&lt;TD class="xl67"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl66" style="height: 15.0pt; width: 48pt;"&gt;5&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;BMI_Y6&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;.&lt;/TD&gt;
&lt;TD class="xl67"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl66" style="height: 15.0pt; width: 48pt;"&gt;6&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;BMI_Y7&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;.&lt;/TD&gt;
&lt;TD class="xl67"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl66" style="height: 15.0pt; width: 48pt;"&gt;7&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;BMI_Y8&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;.&lt;/TD&gt;
&lt;TD class="xl67"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl66" style="height: 15.0pt; width: 48pt;"&gt;8&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;BMI_Y9&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;.&lt;/TD&gt;
&lt;TD class="xl67"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl66" style="height: 15.0pt; width: 48pt;"&gt;9&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;BMI_Y10&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;19.3579&lt;/TD&gt;
&lt;TD class="xl67"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl66" style="height: 15.0pt; width: 48pt;"&gt;10&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;BMI_Y11&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;23.1639&lt;/TD&gt;
&lt;TD class="xl67"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl66" style="height: 15.0pt; width: 48pt;"&gt;11&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;BMI_Y12&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;23.7976&lt;/TD&gt;
&lt;TD class="xl67"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl66" style="height: 15.0pt; width: 48pt;"&gt;12&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;BMI_Y13&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;24.7655&lt;/TD&gt;
&lt;TD class="xl67"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Mon, 30 Sep 2019 15:50:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Substr-function/m-p/592729#M169972</guid>
      <dc:creator>desireatem</dc:creator>
      <dc:date>2019-09-30T15:50:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using Substr function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Substr-function/m-p/592731#M169973</link>
      <description>&lt;P&gt;&lt;SPAN&gt;substr(_NAME_, 4) applied to the first row of your data set produces the result _Y2. Do you see what is wrong now?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2019 15:53:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Substr-function/m-p/592731#M169973</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-09-30T15:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: Using Substr function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Substr-function/m-p/592734#M169975</link>
      <description>Use SCAN() since you have a clear delimiter. &lt;BR /&gt;&lt;BR /&gt;Code = scan(_name_, 2, "_");&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 30 Sep 2019 15:58:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Substr-function/m-p/592734#M169975</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-09-30T15:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using Substr function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Substr-function/m-p/592735#M169976</link>
      <description>&lt;P&gt;Does not work for me.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2019 15:59:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Substr-function/m-p/592735#M169976</guid>
      <dc:creator>desireatem</dc:creator>
      <dc:date>2019-09-30T15:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using Substr function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Substr-function/m-p/592736#M169977</link>
      <description>&lt;P&gt;Thank you. It is now Y2, Y3.., how do I drop the Y so that I have 2, 3, ...&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2019 16:01:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Substr-function/m-p/592736#M169977</guid>
      <dc:creator>desireatem</dc:creator>
      <dc:date>2019-09-30T16:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: Using Substr function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Substr-function/m-p/592738#M169979</link>
      <description>&lt;P&gt;Why not add Y to your SCAN() as a delimiter and you'll get just the number.&lt;/P&gt;
&lt;P&gt;You may need to change 2 to 3 but it's worth trying first.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use INPUT() to convert it to a number, which will likely be your next question, so you can sort correctly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Code = input(scan(_name_, 2, "_Y"), 8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/40563"&gt;@desireatem&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you. It is now Y2, Y3.., how do I drop the Y so that I have 2, 3, ...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2019 16:05:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Substr-function/m-p/592738#M169979</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-09-30T16:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using Substr function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Substr-function/m-p/592739#M169980</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp; You taught me anydigit exactly 19 months ago.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input obs	caseid	_Name_	$ BMI;*	Year;
cards;
1	1	BMI_Y2	.	2
2	1	BMI_Y3	.	3
3	1	BMI_Y4	.	3
4	1	BMI_Y5	.	 
5	1	BMI_Y6	.	 
6	1	BMI_Y7	.	 
7	1	BMI_Y8	.	 
8	1	BMI_Y9	.	 
9	1	BMI_Y10	19.3579	 
10	1	BMI_Y11	23.1639	 
11	1	BMI_Y12	23.7976	 
12	1	BMI_Y13	24.7655	 
;

data want;
set have;
year=substr(_name_, anydigit(_Name_));
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Sep 2019 16:04:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Substr-function/m-p/592739#M169980</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-30T16:04:20Z</dc:date>
    </item>
    <item>
      <title>Re: Using Substr function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Substr-function/m-p/592740#M169981</link>
      <description>&lt;P&gt;Or Compress with 'kd' modifier&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input obs	caseid	_Name_	$ BMI;*	Year;
cards;
1	1	BMI_Y2	.	2
2	1	BMI_Y3	.	3
3	1	BMI_Y4	.	3
4	1	BMI_Y5	.	 
5	1	BMI_Y6	.	 
6	1	BMI_Y7	.	 
7	1	BMI_Y8	.	 
8	1	BMI_Y9	.	 
9	1	BMI_Y10	19.3579	 
10	1	BMI_Y11	23.1639	 
11	1	BMI_Y12	23.7976	 
12	1	BMI_Y13	24.7655	 
;

data want;
set have;
year=compress(_name_,,'kd');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Sep 2019 16:06:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Substr-function/m-p/592740#M169981</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-30T16:06:11Z</dc:date>
    </item>
    <item>
      <title>Re: Using Substr function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Substr-function/m-p/592741#M169982</link>
      <description>&lt;P&gt;Thank you very much for your help!&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2019 16:06:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Substr-function/m-p/592741#M169982</guid>
      <dc:creator>desireatem</dc:creator>
      <dc:date>2019-09-30T16:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: Using Substr function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Substr-function/m-p/592742#M169983</link>
      <description>Yup, there's many ways to slice this one. &lt;BR /&gt;Another viable option is COMPRESS() which will keep only digits. &lt;BR /&gt;&lt;BR /&gt;compress(_name_, , 'kd');&lt;BR /&gt;</description>
      <pubDate>Mon, 30 Sep 2019 16:06:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Substr-function/m-p/592742#M169983</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-09-30T16:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: Using Substr function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Substr-function/m-p/592744#M169984</link>
      <description>&lt;P&gt;Reeza's special in my notes :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Proc freq &lt;STRONG&gt;sparse&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;2. &lt;STRONG&gt;Any&lt;/STRONG&gt;...... group of functions with precisions&lt;/P&gt;
&lt;P&gt;3. Not to trust anydate informats unless you know for real and sure&lt;/P&gt;
&lt;P&gt;4. Remerge in SQL if system is fast enough and convenient&lt;/P&gt;
&lt;P&gt;5. Informat statement better than a colon format modifier for reading ease&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and the list goes on to 143 points so far. I am definitely not sharing all. It's my selfish effort to take notes. lol But kudos for offering lol &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2019 16:11:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Substr-function/m-p/592744#M169984</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-30T16:11:00Z</dc:date>
    </item>
  </channel>
</rss>

