<?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: How to use SUBSTRN in macro function as used in data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-SUBSTRN-in-macro-function-as-used-in-data-step/m-p/750592#M236125</link>
    <description>&lt;P&gt;Does the beginning of &amp;amp;TITLES always contain a number in the form ##.#. ?&amp;nbsp; If so, you could use a direct approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let file_title1 = %scan(&amp;amp;titles, 1, .).%scan(&amp;amp;titles, 2, .).  &amp;amp;title1;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 26 Jun 2021 11:00:45 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2021-06-26T11:00:45Z</dc:date>
    <item>
      <title>How to use SUBSTRN in macro function as used in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-SUBSTRN-in-macro-function-as-used-in-data-step/m-p/750589#M236123</link>
      <description>&lt;P&gt;Hello ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to use 'SUBSTRN'&amp;nbsp; in macro code , but when use this one gettng errors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;we can use %ksubstr in macro , but how to use 'SUBSTRN' in macro code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is my exist code in data step , but would like to write in macro code to assing macro varible value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let titles=listing 16-88.4. many text many text words;
%let title1= Subject listing by devations;
data&amp;nbsp; test;
&amp;nbsp; titles=symget('titles');
&amp;nbsp; title1=symget(title1);
&amp;nbsp; file_title1=substrn(titles,1,find(titles,' ')),title1);
run;
output is = file_title1="listing 16-88.4. Subject listing by devations";&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;woudl like to write above cod in macro to assing to macor varible like below but i am getting errors, please help me to for this issue, but not use cally symput in data step to create macro varible or proc sql.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let file_title1=%ksubstrn(&amp;amp;titles,1,%kfind(&amp;amp;titles,' ')&amp;amp;title1);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 10:29:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-SUBSTRN-in-macro-function-as-used-in-data-step/m-p/750589#M236123</guid>
      <dc:creator>raja777pharma</dc:creator>
      <dc:date>2021-06-26T10:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to use SUBSTRN in macro function as used in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-SUBSTRN-in-macro-function-as-used-in-data-step/m-p/750590#M236124</link>
      <description>&lt;P&gt;You need to enclose SUBSTRN (or any data step function) inside %sysfunc&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let file_title1 = %sysfunc(substrn(&amp;amp;titles,1,%kfind(&amp;amp;titles,' ')&amp;amp;title1));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 26 Jun 2021 10:37:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-SUBSTRN-in-macro-function-as-used-in-data-step/m-p/750590#M236124</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-26T10:37:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to use SUBSTRN in macro function as used in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-SUBSTRN-in-macro-function-as-used-in-data-step/m-p/750592#M236125</link>
      <description>&lt;P&gt;Does the beginning of &amp;amp;TITLES always contain a number in the form ##.#. ?&amp;nbsp; If so, you could use a direct approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let file_title1 = %scan(&amp;amp;titles, 1, .).%scan(&amp;amp;titles, 2, .).  &amp;amp;title1;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 26 Jun 2021 11:00:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-SUBSTRN-in-macro-function-as-used-in-data-step/m-p/750592#M236125</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-06-26T11:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to use SUBSTRN in macro function as used in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-SUBSTRN-in-macro-function-as-used-in-data-step/m-p/750595#M236127</link>
      <description>&lt;P&gt;Been there. Done that.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sasutils/macros/blob/master/substrn.sas" target="_self"&gt;%substrn()&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sasutils/macros/blob/master/qsubstrn.sas" target="_self"&gt;%qsubstrn()&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 11:53:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-SUBSTRN-in-macro-function-as-used-in-data-step/m-p/750595#M236127</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-26T11:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to use SUBSTRN in macro function as used in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-SUBSTRN-in-macro-function-as-used-in-data-step/m-p/750648#M236147</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/309000"&gt;@raja777pharma&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We need to take this in several steps.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First thing is that your data step doesn't work. There are two errors:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ErikLund_Jensen_0-1624785424383.png" style="width: 568px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60779i1AE16AE87E49B626/image-dimensions/568x152?v=v2" width="568" height="152" role="button" title="ErikLund_Jensen_0-1624785424383.png" alt="ErikLund_Jensen_0-1624785424383.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;You dont' get a value in title1, because the argument to symget should be quoted like in the line above.&lt;/LI&gt;
&lt;LI&gt;The substrn function takes max. 3 arguments, but you have added title1 as a fourth argument. If you want to concatenate the value of title1 to the substring, you need to use either a concatenation operator or a CAT function.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I need to ask a question about your wanted output, because when the errors are fixed, the result is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ErikLund_Jensen_2-1624786134286.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60781i68EEFBDD2AD7A5D9/image-size/large?v=v2&amp;amp;px=999" role="button" title="ErikLund_Jensen_2-1624786134286.png" alt="ErikLund_Jensen_2-1624786134286.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I expect your wanted output to be the string "&lt;STRONG&gt;&lt;EM&gt;listing 16-88.4. Subject listing by devations&lt;/EM&gt;&lt;/STRONG&gt;", but that is not what you get, because you take a substring from start to first blank character, so the number part is omitted. And a move from a data step to macro code wouldn't change that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would be easier to forget about substringing and use scan instead, so you can pick the strings you want regardless of length:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let titles=listing 16-88.4. many text many text words;
%let title1= Subject listing by devations;
%let file_title = %scan(&amp;amp;titles,1,%str( )) %scan(&amp;amp;titles,2,%str( )) &amp;amp;title1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This gives:&lt;/P&gt;
&lt;P&gt;listing 16-88.4. Subject listing by devations&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck&lt;/P&gt;
&lt;P&gt;Erik&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;, because the not what you get from your data step. You take a substring from start to first blank character, so the step actually gives&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Jun 2021 09:41:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-SUBSTRN-in-macro-function-as-used-in-data-step/m-p/750648#M236147</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2021-06-27T09:41:26Z</dc:date>
    </item>
  </channel>
</rss>

