<?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: keep all char after specific position of hyphen in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/keep-all-char-after-specific-position-of-hyphen/m-p/816495#M322296</link>
    <description>&lt;P&gt;You cannot use CALL routines in SQL. What you can do is use PROC FCMP to write a function that calls the routine:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  v1="11-abc-def-1234-q111";
run;

options cmplib=work.funcs;
proc fcmp outlib=work.funcs.strings;
  function remain_str(string $,n,delimiters $) $200;
    p=0;
    len=0;
    call scan(string,n,p,len,delimiters);
    if p&amp;gt;0 then
      return(substr(string,p));
    else return ('');
    endfunc;
run;
proc sql;
  select v1,remain_str(v1,4,'-') as result from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 04 Jun 2022 11:15:19 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2022-06-04T11:15:19Z</dc:date>
    <item>
      <title>keep all char after specific position of hyphen</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-all-char-after-specific-position-of-hyphen/m-p/816409#M322240</link>
      <description>&lt;P&gt;This should be a simple question. I have a string, e.g a variable called "v1" that has value of "11-abc-def-1234-q111". I want to just keep all after the third hyphen. So, the result should be "1234-q111". I used scan(v1, 4, '-') it just gave me "1234". I tried to use catx (scan(v1, 4, '-'), scan(v1, 5, '-')). I still cannot get the result wanted. I felt it is about the position index i used, but not sure. Any help would be appreciated.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jun 2022 19:44:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-all-char-after-specific-position-of-hyphen/m-p/816409#M322240</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2022-06-03T19:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: keep all char after specific position of hyphen</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-all-char-after-specific-position-of-hyphen/m-p/816412#M322242</link>
      <description>&lt;P&gt;Similar to what you tried with SCAN but using CALL SCAN to find the position of the 4th word.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;45         data _null_;
46            x="11-abc-def-1234-q111";
47            call scan(x,4,p,_n_);
48            s=substr(x,p);
49            put _all_;
50            run;

x=11-abc-def-1234-q111 p=12 s=1234-q111 _ERROR_=0 _N_=4&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Jun 2022 19:56:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-all-char-after-specific-position-of-hyphen/m-p/816412#M322242</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2022-06-03T19:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: keep all char after specific position of hyphen</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-all-char-after-specific-position-of-hyphen/m-p/816414#M322243</link>
      <description>&lt;P&gt;Thanks for your reply. I am using the variable "v1" in proc sql to create anther variable which is the substred value. Would call scan work in proc sql?&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jun 2022 19:59:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-all-char-after-specific-position-of-hyphen/m-p/816414#M322243</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2022-06-03T19:59:12Z</dc:date>
    </item>
    <item>
      <title>Re: keep all char after specific position of hyphen</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-all-char-after-specific-position-of-hyphen/m-p/816430#M322249</link>
      <description>&lt;P&gt;I would look at the documentation if I were you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/84484"&gt;@sasecn&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your reply. I am using the variable "v1" in proc sql to create anther variable which is the substred value. Would call scan work in proc sql?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jun 2022 20:34:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-all-char-after-specific-position-of-hyphen/m-p/816430#M322249</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2022-06-03T20:34:48Z</dc:date>
    </item>
    <item>
      <title>Re: keep all char after specific position of hyphen</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-all-char-after-specific-position-of-hyphen/m-p/816495#M322296</link>
      <description>&lt;P&gt;You cannot use CALL routines in SQL. What you can do is use PROC FCMP to write a function that calls the routine:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  v1="11-abc-def-1234-q111";
run;

options cmplib=work.funcs;
proc fcmp outlib=work.funcs.strings;
  function remain_str(string $,n,delimiters $) $200;
    p=0;
    len=0;
    call scan(string,n,p,len,delimiters);
    if p&amp;gt;0 then
      return(substr(string,p));
    else return ('');
    endfunc;
run;
proc sql;
  select v1,remain_str(v1,4,'-') as result from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 Jun 2022 11:15:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-all-char-after-specific-position-of-hyphen/m-p/816495#M322296</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2022-06-04T11:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: keep all char after specific position of hyphen</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-all-char-after-specific-position-of-hyphen/m-p/816497#M322298</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/84484"&gt;@sasecn&lt;/a&gt;,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/84484"&gt;@sasecn&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I tried to use catx (scan(v1, 4, '-'), scan(v1, 5, '-')).&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You just forgot the first argument of the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n0p7wxtk0hvn83n1pveisbcp2ae9.htm" target="_blank" rel="noopener"&gt;CATX function&lt;/A&gt;, the delimiter:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;catx(&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;'-',&lt;/STRONG&gt;&lt;/FONT&gt; scan(v1, 4, '-'), scan(v1, 5, '-'))&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the number of hyphens in V1 was not limited to four, you could nest &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0wqoixcwtx2jqn1ovqf06kart0o.htm" target="_blank" rel="noopener"&gt;SUBSTRN&lt;/A&gt; and &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p00ab6ey29t2i8n1ihel88tqtga9.htm" target="_blank" rel="noopener"&gt;FIND function&lt;/A&gt; calls, but make sure that at least three hyphens are present. In PROC SQL:&lt;/P&gt;
&lt;PRE&gt;select v1, case when countc(v1,'-')&amp;gt;=3
                then substrn(v1,find(v1,'-',find(v1,'-',find(v1,'-')+1)+1)+1)
                else ' '
           end as want&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 Jun 2022 12:27:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-all-char-after-specific-position-of-hyphen/m-p/816497#M322298</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-06-04T12:27:46Z</dc:date>
    </item>
  </channel>
</rss>

