<?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: Question about SUBSTR function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618372#M181401</link>
    <description>&lt;P&gt;Don't let the &lt;STRONG&gt;bugs&lt;/STRONG&gt; in the auto-indent function of the SAS editors cause you to generate difficult to maintain SAS code.&lt;/P&gt;
&lt;P&gt;Always place the DATALINES (aka CARDS) statement in the FIRST column.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you have done that the auto-indent should put the cursor in the first column for the lines of data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Example;
  Input abc $12.;
datalines;
083154564684
783480645621
384563604852
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also do not enter tabs into program files. There are options in the various SAS editors to replace tabs with spaces. You can still use the TAB key while typing to help keep your program lines indented consistently, but the presence of tabs in the actual file just leads to this type of confusion.&lt;/P&gt;</description>
    <pubDate>Sun, 19 Jan 2020 16:10:53 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-01-19T16:10:53Z</dc:date>
    <item>
      <title>Question about SUBSTR function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618314#M181379</link>
      <description>&lt;P&gt;I got this coding exercise to extract certain length of characters from a given data set:&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; Data Example;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; Input abc $12.;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; Datalines;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; 08315&lt;/FONT&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;456&lt;/SPAN&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;4684&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; 7834806&lt;/FONT&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;456&lt;/SPAN&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;21&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; 384563604852&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; ;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; Run&lt;/FONT&gt;;&lt;/P&gt;&lt;P&gt;The task is to extract the # from &lt;U&gt;2nd to 6th digits&lt;/U&gt;. So I put &lt;FONT face="courier new,courier"&gt;num = SUBSTR(abc,2,5);&lt;/FONT&gt;. But instead it returned an extraction from &lt;U&gt;1st to 5th digits&lt;/U&gt;, aka "&lt;FONT face="courier new,courier"&gt;08315, 78348, 38456&lt;/FONT&gt;". Why is it???&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I looked into this &lt;FONT face="courier new,courier"&gt;Example&lt;/FONT&gt; data set and found out all the last digits of those numbers were missing... I'm confused now and not sure if the above problem is somewhat related to it.&amp;nbsp;&lt;img id="robotsad" class="emoticon emoticon-robotsad" src="https://communities.sas.com/i/smilies/16x16_robot-sad.png" alt="Robot Sad" title="Robot Sad" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(BTW I'm a beginner and I use the SAS University Edition for Windows.)&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jan 2020 02:33:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618314#M181379</guid>
      <dc:creator>PekingDuck</dc:creator>
      <dc:date>2020-01-19T02:33:00Z</dc:date>
    </item>
    <item>
      <title>Re: Question about SUBSTR function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618315#M181380</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; Data Example;
    Input abc $12.;
    Datalines;
    083154564684
    783480645621
    384563604852
    ;
    Run;

data want;
 set example;
 num = SUBSTR(abc,2,5);
run;

proc print noobs;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;abc num&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;08315456 83154&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;78348064 83480&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;38456360 84563&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What's the problem with your test?&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jan 2020 02:56:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618315#M181380</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-19T02:56:55Z</dc:date>
    </item>
    <item>
      <title>Re: Question about SUBSTR function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618319#M181382</link>
      <description>Post your log.</description>
      <pubDate>Sun, 19 Jan 2020 03:11:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618319#M181382</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-19T03:11:53Z</dc:date>
    </item>
    <item>
      <title>Re: Question about SUBSTR function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618322#M181384</link>
      <description>&lt;P&gt;Thank you for your reply &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Mine gave me the result like the following -&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;08315456468 --&amp;gt; 08315&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;78348064562 --&amp;gt; 78348&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;38456360485 --&amp;gt; 38456&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I just tried and set the second parameter as &lt;STRONG&gt;3&lt;/STRONG&gt; instead of &lt;STRONG&gt;2&lt;/STRONG&gt;, this way could get the correct output...(???)&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jan 2020 03:34:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618322#M181384</guid>
      <dc:creator>PekingDuck</dc:creator>
      <dc:date>2020-01-19T03:34:40Z</dc:date>
    </item>
    <item>
      <title>Re: Question about SUBSTR function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618323#M181385</link>
      <description>&lt;P&gt;Plz post your&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. full code&lt;/P&gt;
&lt;P&gt;2 log&lt;/P&gt;
&lt;P&gt;3 output&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so the community members can give you an informed suggestion&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jan 2020 03:36:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618323#M181385</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-19T03:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: Question about SUBSTR function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618324#M181386</link>
      <description>&lt;PRE&gt;Data Example;
	Input abc $12.;
	Datalines;
	083154564684
	783480645621
	384563604852
	;
Run;

data test;
	set example;
	num = SUBSTR(abc,2,5);
run;&lt;/PRE&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;Output:&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&lt;STRONG&gt;abc num&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;08315456468 08315&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;78348064562 78348&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;38456360485 38456&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&lt;DIV class="sasSource"&gt;Log:&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;72&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;73 Data Example;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;74 Input abc $12.;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;75 Datalines;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: The data set WORK.EXAMPLE has 3 observations and 1 variables.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: DATA statement used (Total process time):&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;real time 0.00 seconds&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;cpu time 0.00 seconds&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;79 ;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;80 Run;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;81&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;82 data test;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;83 set example;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;84 num = SUBSTR(abc,2,5);&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;85 run;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: There were 3 observations read from the data set WORK.EXAMPLE.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: The data set WORK.TEST has 3 observations and 2 variables.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: DATA statement used (Total process time):&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;real time 0.01 seconds&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;cpu time 0.00 seconds&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;86&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;87 proc print noobs;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;88 run;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: There were 3 observations read from the data set WORK.TEST.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: PROCEDURE PRINT used (Total process time):&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;real time 0.02 seconds&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;cpu time 0.03 seconds&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sun, 19 Jan 2020 03:49:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618324#M181386</guid>
      <dc:creator>PekingDuck</dc:creator>
      <dc:date>2020-01-19T03:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: Question about SUBSTR function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618325#M181387</link>
      <description>&lt;P&gt;Hello. Please refer to my reply to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&amp;nbsp;&lt;img id="robothappy" class="emoticon emoticon-robothappy" src="https://communities.sas.com/i/smilies/16x16_robot-happy.png" alt="Robot Happy" title="Robot Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jan 2020 03:51:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618325#M181387</guid>
      <dc:creator>PekingDuck</dc:creator>
      <dc:date>2020-01-19T03:51:07Z</dc:date>
    </item>
    <item>
      <title>Re: Question about SUBSTR function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618326#M181388</link>
      <description>&lt;P&gt;Jeez, that's strange. Okay, is there any chance of an unlikely occurence of a leading blank or control characters?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If at all there is, can you try STRIPPING the blanks?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	num = SUBSTR(strip(abc),2,5);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 19 Jan 2020 03:57:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618326#M181388</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-19T03:57:13Z</dc:date>
    </item>
    <item>
      <title>Re: Question about SUBSTR function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618328#M181389</link>
      <description>&lt;P&gt;your input stmt is reading the tab character you entered while typing the data.&amp;nbsp; With your code I got the same results as you. When I removed it (see below) I got the right answer.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Example;
	Input abc $12.;
	Datalines;
083154564684
783480645621
384563604852
	;
Run;

data test;
	set example;
	num = SUBSTR(abc,2,5);
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 19 Jan 2020 04:03:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618328#M181389</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2020-01-19T04:03:51Z</dc:date>
    </item>
    <item>
      <title>Re: Question about SUBSTR function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618330#M181391</link>
      <description>&lt;P&gt;Nah. No luck with your solution.&lt;/P&gt;&lt;P&gt;But you did give me the idea of what's wrong. I realized the leading tab I entered before the data caused the problem... So the position of those digits shifted in the output.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Forgive me of this stupid mistake (facepalm)&amp;nbsp;&lt;/P&gt;&lt;P&gt;And thanks for your help!&amp;nbsp;&lt;img id="robotwink" class="emoticon emoticon-robotwink" src="https://communities.sas.com/i/smilies/16x16_robot-wink.png" alt="Robot wink" title="Robot wink" /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jan 2020 04:14:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618330#M181391</guid>
      <dc:creator>PekingDuck</dc:creator>
      <dc:date>2020-01-19T04:14:13Z</dc:date>
    </item>
    <item>
      <title>Re: Question about SUBSTR function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618331#M181392</link>
      <description>&lt;P&gt;good eye&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jan 2020 04:17:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618331#M181392</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2020-01-19T04:17:02Z</dc:date>
    </item>
    <item>
      <title>Re: Question about SUBSTR function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618333#M181394</link>
      <description>&lt;P&gt;Hello. Yes, I found out about it just a minute ago... Such a rookie mistake @_@.&lt;/P&gt;&lt;P&gt;Thanks very much!&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jan 2020 04:18:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618333#M181394</guid>
      <dc:creator>PekingDuck</dc:creator>
      <dc:date>2020-01-19T04:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: Question about SUBSTR function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618372#M181401</link>
      <description>&lt;P&gt;Don't let the &lt;STRONG&gt;bugs&lt;/STRONG&gt; in the auto-indent function of the SAS editors cause you to generate difficult to maintain SAS code.&lt;/P&gt;
&lt;P&gt;Always place the DATALINES (aka CARDS) statement in the FIRST column.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you have done that the auto-indent should put the cursor in the first column for the lines of data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Example;
  Input abc $12.;
datalines;
083154564684
783480645621
384563604852
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also do not enter tabs into program files. There are options in the various SAS editors to replace tabs with spaces. You can still use the TAB key while typing to help keep your program lines indented consistently, but the presence of tabs in the actual file just leads to this type of confusion.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jan 2020 16:10:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618372#M181401</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-19T16:10:53Z</dc:date>
    </item>
    <item>
      <title>Re: Question about SUBSTR function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618447#M181438</link>
      <description>&lt;P&gt;Hello Tom.&amp;nbsp; I appreciate the information and advice you've shared.&lt;/P&gt;&lt;P&gt;People here are so helpful and I've learned a lot from you guys just on this one simple/basic problem, which is very encouraging for me as a beginner.&amp;nbsp;&lt;img id="robotvery-happy" class="emoticon emoticon-robotvery-happy" src="https://communities.sas.com/i/smilies/16x16_robot-very-happy.png" alt="Robot Very Happy" title="Robot Very Happy" /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2020 02:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-SUBSTR-function/m-p/618447#M181438</guid>
      <dc:creator>PekingDuck</dc:creator>
      <dc:date>2020-01-20T02:40:40Z</dc:date>
    </item>
  </channel>
</rss>

