<?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: Problem with using substring together with %sysfunc in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-using-substring-together-with-sysfunc/m-p/405210#M98550</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can extract the year with prxchange as follows :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let a=datafile2016.xlsx;&lt;BR /&gt;%let b=%sysfunc(prxchange(s/.*(20\d{2}).*/$1/,-1,&amp;amp;a.));&lt;/P&gt;</description>
    <pubDate>Wed, 18 Oct 2017 13:56:06 GMT</pubDate>
    <dc:creator>gamotte</dc:creator>
    <dc:date>2017-10-18T13:56:06Z</dc:date>
    <item>
      <title>Problem with using substring together with %sysfunc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-using-substring-together-with-sysfunc/m-p/405204#M98546</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a macro that imports all Excel files in a given directory. The name of each Excel file contains information about year that I want to later use. However, in different files, the position of the year is different, e.g. datafile2016.xlsx, datafile2016_upd.xlsx etc.&lt;/P&gt;
&lt;P&gt;I want to create a macro variable that extracts the year from each name of the file. My idea is to use nested substring and index functions:&lt;/P&gt;
&lt;P&gt;year=substr(&amp;amp;name, x, 4), where x is the position of the "20" substring (first two digits of the year) that I find by using: index(&amp;amp;name, "20") and &amp;amp;name contains whole name of the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since I'm doing this in the macro, I use %sysfunc with each function, which gives me the following code:&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 year=%sysfunc(%substr(&amp;amp;name, %sysfunc(inputn(%sysfunc(index(&amp;amp;name, "20")), 2.)), 4));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, this produces the following error: ERROR: Function name missing in %SYSFUNC or %QSYSFUNC macro function reference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What am I doing wrong?&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 13:41:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-using-substring-together-with-sysfunc/m-p/405204#M98546</guid>
      <dc:creator>chris2377</dc:creator>
      <dc:date>2017-10-18T13:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with using substring together with %sysfunc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-using-substring-together-with-sysfunc/m-p/405208#M98548</link>
      <description>&lt;P&gt;%SYSFUNC is only need to permit macro language to utilize a non-macro function.&amp;nbsp; The first %SYSFUNC should be removed, since %SUBSTR is a macro function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may have other issues once this error is gone.&amp;nbsp; It's likely you need to remove the quotes around "20" since macro language would take that to be a four-character string.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 13:52:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-using-substring-together-with-sysfunc/m-p/405208#M98548</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-10-18T13:52:00Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with using substring together with %sysfunc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-using-substring-together-with-sysfunc/m-p/405210#M98550</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can extract the year with prxchange as follows :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let a=datafile2016.xlsx;&lt;BR /&gt;%let b=%sysfunc(prxchange(s/.*(20\d{2}).*/$1/,-1,&amp;amp;a.));&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 13:56:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-using-substring-together-with-sysfunc/m-p/405210#M98550</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2017-10-18T13:56:06Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with using substring together with %sysfunc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-using-substring-together-with-sysfunc/m-p/405211#M98551</link>
      <description>Thanks. I did both and it works now!</description>
      <pubDate>Wed, 18 Oct 2017 13:57:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-using-substring-together-with-sysfunc/m-p/405211#M98551</guid>
      <dc:creator>chris2377</dc:creator>
      <dc:date>2017-10-18T13:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with using substring together with %sysfunc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-using-substring-together-with-sysfunc/m-p/405220#M98553</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30622"&gt;@gamotte&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks. That's another approach. I promise to myself that one day I'll learn Pearl regular expressions in SAS &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 14:19:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-using-substring-together-with-sysfunc/m-p/405220#M98553</guid>
      <dc:creator>chris2377</dc:creator>
      <dc:date>2017-10-18T14:19:27Z</dc:date>
    </item>
  </channel>
</rss>

