<?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: Macro Substr &amp;amp; length in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Substr-amp-length/m-p/311983#M67583</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am in agreement with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen﻿&lt;/a&gt;&amp;nbsp;here, there seems to be no point to this code, other than to obfuscate code? &amp;nbsp;Substr is a datastep function, not a macro function - so nothing like %susbtr(). &amp;nbsp;Create your question using the guidance provided. &amp;nbsp;Provide test data - in the form of a datastep, and examplpe of what the output should look like.&lt;/P&gt;</description>
    <pubDate>Wed, 16 Nov 2016 14:09:16 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-11-16T14:09:16Z</dc:date>
    <item>
      <title>Macro Substr &amp; length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Substr-amp-length/m-p/311978#M67580</link>
      <description>&lt;P&gt;CODE:&lt;BR /&gt;%macro ss(s=);&lt;BR /&gt;&lt;BR /&gt;data d;&lt;BR /&gt;a=%substr("&amp;amp;s",2,%length(&amp;amp;s)-3)dy;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;%mend;&lt;BR /&gt;&lt;BR /&gt;%ss(s=cmstdtc)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OUTPUT:&lt;/P&gt;&lt;P&gt;a=cmstdy&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If im giving the substr position as 1 its not working but, if i give the position as 2 its working correctly. i want to know how this code works.Plz check the answer for a in log using "options mprint symbolgen".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 13:53:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Substr-amp-length/m-p/311978#M67580</guid>
      <dc:creator>ramuking003</dc:creator>
      <dc:date>2016-11-16T13:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Substr &amp; length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Substr-amp-length/m-p/311980#M67581</link>
      <description>&lt;P&gt;Please describe what you are trying to accomplish with your code? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 14:00:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Substr-amp-length/m-p/311980#M67581</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2016-11-16T14:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Substr &amp; length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Substr-amp-length/m-p/311982#M67582</link>
      <description>&lt;P&gt;The macro language does not use quotation marks to indicate a text value.&amp;nbsp; In the macro language, all values are text, so they are not needed.&amp;nbsp; If you use quote marks they become part of the value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below shows the quote marks are part of the value:&lt;/P&gt;
&lt;PRE&gt;37   %let s=cmstdtc;
38   %put The length of macro var S is: %length(&amp;amp;s);
The length of macro var S is: 7
39   %put The length of macro var S with quote marks is: %length("&amp;amp;s");
The length of macro var S with quote marks is: 9
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's a macro best practice to avoid adding quote marks to your values.&amp;nbsp; If you choose to add quote marks, you need to remember that they are there, and account for them, which is why starting at position two works:&lt;/P&gt;
&lt;PRE&gt;40   %put %substr("&amp;amp;s",2,%length(&amp;amp;s)-3)dy;
cmstdy

&lt;/PRE&gt;
&lt;P&gt;If you started at position 1, the quote mark would be part of the value returned by %substr()&amp;nbsp; [and you would end up with unmatched quoation marks].&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you avoid adding the quote marks, you can start at position one, as you would expect:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;41   %put %substr(&amp;amp;s,1,%length(&amp;amp;s)-3)dy;
cmstdy&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The quote marks are needed in the SAS language to indicate that a literal value is character rather than numeric.&amp;nbsp; In the macro language, all values are character, so quotation marks are not used to to indicate character values.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 14:11:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Substr-amp-length/m-p/311982#M67582</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2016-11-16T14:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Substr &amp; length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Substr-amp-length/m-p/311983#M67583</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am in agreement with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen﻿&lt;/a&gt;&amp;nbsp;here, there seems to be no point to this code, other than to obfuscate code? &amp;nbsp;Substr is a datastep function, not a macro function - so nothing like %susbtr(). &amp;nbsp;Create your question using the guidance provided. &amp;nbsp;Provide test data - in the form of a datastep, and examplpe of what the output should look like.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 14:09:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Substr-amp-length/m-p/311983#M67583</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-11-16T14:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Substr &amp; length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Substr-amp-length/m-p/311984#M67584</link>
      <description>&lt;P&gt;Hi ramuking,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The reason you are experiencing the error when you change the "start" portionof the %substr to 1 if the quotation marks you have used on the "source" portion of the %substr.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Macro language, unlike dataset, is purely text.&amp;nbsp; So there is no need for you to use quotations in your %substr function, as text is all it will read.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So when you are including the quotation marks the result you are getting from the %substr is &lt;STRONG&gt;&lt;EM&gt;"cmsdy&lt;/EM&gt;&lt;/STRONG&gt;, making your datastep read:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;data d;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;a = "cmsdy;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;run;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;and this is why it does not work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In contrast, when you used 2 as your "start" your %substr function return &lt;STRONG&gt;&lt;EM&gt;cmstdy, &lt;/EM&gt;&lt;/STRONG&gt;making your datastep read:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;data d;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;a = cmstdy;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;run;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;as you desired.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So long story short, don't include the quotation marks in the source portion of your %substr function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 14:14:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Substr-amp-length/m-p/311984#M67584</guid>
      <dc:creator>BenbowL</dc:creator>
      <dc:date>2016-11-16T14:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Substr &amp; length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Substr-amp-length/m-p/311987#M67586</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are messing things. You try applying macro functions in order to set data variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro functions shall be used to manipulate macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just answering your question - the code works in terms of no error message but if you look at the database created, the values&lt;/P&gt;
&lt;P&gt;are missing therefore in fact the code does not work.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 14:16:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Substr-amp-length/m-p/311987#M67586</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2016-11-16T14:16:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Substr &amp; length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Substr-amp-length/m-p/312196#M67676</link>
      <description>&lt;P&gt;Thank you. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 04:33:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Substr-amp-length/m-p/312196#M67676</guid>
      <dc:creator>ramuking003</dc:creator>
      <dc:date>2016-11-17T04:33:33Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Substr &amp; length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Substr-amp-length/m-p/312198#M67678</link>
      <description>&lt;P&gt;Now i understood what mistake i have done thank you. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 04:38:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Substr-amp-length/m-p/312198#M67678</guid>
      <dc:creator>ramuking003</dc:creator>
      <dc:date>2016-11-17T04:38:49Z</dc:date>
    </item>
  </channel>
</rss>

