<?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: Extract the characters before the second &amp;quot;-&amp;quot; in the value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-characters-before-the-second-quot-quot-in-the-value/m-p/686202#M208188</link>
    <description>&lt;P&gt;This should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;want = catx('-', scan(string, 1, '-'), scan(string, 2, '-') );&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 23 Sep 2020 20:10:56 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2020-09-23T20:10:56Z</dc:date>
    <item>
      <title>Extract the characters before the second "-" in the value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-characters-before-the-second-quot-quot-in-the-value/m-p/686168#M208168</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to extract the characters before the second "-" in the value (name is pagepath). Any ideas or thoughts are appreciated!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 18:20:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-characters-before-the-second-quot-quot-in-the-value/m-p/686168#M208168</guid>
      <dc:creator>yichentian226</dc:creator>
      <dc:date>2020-09-23T18:20:58Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the characters before the second "-" in the value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-characters-before-the-second-quot-quot-in-the-value/m-p/686173#M208170</link>
      <description>SCAN() or a regex.</description>
      <pubDate>Wed, 23 Sep 2020 19:06:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-characters-before-the-second-quot-quot-in-the-value/m-p/686173#M208170</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-09-23T19:06:10Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the characters before the second "-" in the value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-characters-before-the-second-quot-quot-in-the-value/m-p/686174#M208171</link>
      <description>&lt;P&gt;Thanks for the reply, I used scan function and I could extract characters before the first "-", but I'm not sure how to extract characters before the second "-". Here's an example, abc-def-ghi, I want to get result as "abc-def".&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 19:09:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-characters-before-the-second-quot-quot-in-the-value/m-p/686174#M208171</guid>
      <dc:creator>yichentian226</dc:creator>
      <dc:date>2020-09-23T19:09:02Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the characters before the second "-" in the value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-characters-before-the-second-quot-quot-in-the-value/m-p/686176#M208172</link>
      <description>&lt;P&gt;Show your code. What did you put as the second and third parameters?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p0jshdjy2z9zdzn1h7k90u99lyq6.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;&lt;SPAN class="xisDoc-keyword"&gt;SCAN&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;&lt;A tabindex="0" title="“string”" href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p0jshdjy2z9zdzn1h7k90u99lyq6.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#p0ctpo1650lomun1cddyc1rodmh1" data-docset-id="lefunctionsref" data-docset-version="9.4" data-original-href="p0jshdjy2z9zdzn1h7k90u99lyq6.htm#p0ctpo1650lomun1cddyc1rodmh1"&gt;string&lt;/A&gt;&lt;/EM&gt;&lt;SPAN&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;&lt;A tabindex="0" title="“count”" href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p0jshdjy2z9zdzn1h7k90u99lyq6.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#p00b11fwb79wk4n1jvl4hiobbcng" data-docset-id="lefunctionsref" data-docset-version="9.4" data-original-href="p0jshdjy2z9zdzn1h7k90u99lyq6.htm#p00b11fwb79wk4n1jvl4hiobbcng"&gt;count&lt;/A&gt;&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="xisDoc-optional"&gt;&amp;lt;,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;&lt;A tabindex="0" title="“character-list”" href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p0jshdjy2z9zdzn1h7k90u99lyq6.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#p13y5i05dpp62pn1p2tl9zlk0wn0" data-docset-id="lefunctionsref" data-docset-version="9.4" data-original-href="p0jshdjy2z9zdzn1h7k90u99lyq6.htm#p13y5i05dpp62pn1p2tl9zlk0wn0"&gt;character-list&lt;/A&gt;&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;lt;,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;&lt;A tabindex="0" title="“modifier”" href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p0jshdjy2z9zdzn1h7k90u99lyq6.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#n125492vxo9uxmn19esm1g0eezji" data-docset-id="lefunctionsref" data-docset-version="9.4" data-original-href="p0jshdjy2z9zdzn1h7k90u99lyq6.htm#n125492vxo9uxmn19esm1g0eezji"&gt;modifier&lt;/A&gt;&lt;/EM&gt;&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&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;</description>
      <pubDate>Wed, 23 Sep 2020 19:12:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-characters-before-the-second-quot-quot-in-the-value/m-p/686176#M208172</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-09-23T19:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the characters before the second "-" in the value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-characters-before-the-second-quot-quot-in-the-value/m-p/686180#M208174</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/318223"&gt;@yichentian226&lt;/a&gt;&amp;nbsp; &amp;nbsp;Here's one way to do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    input pagepath $25.;
    datalines;
    abc-def-ghi-jkl
    testing-it-again
    ;
run;

data want (drop=p i);
    set have;
    p = 0;
    do i=1 to 2 until(p=0); 
        p = find(pagepath, '-', p+1);
    end;
    if p ne 0 then str_before_2nd_hyphen = substr(pagepath, 1, p-1);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Reference:&amp;nbsp;&amp;nbsp;&lt;A href="https://blogs.sas.com/content/sgf/2019/06/26/finding-n-th-instance-of-a-substring-within-a-string/" target="_blank"&gt;https://blogs.sas.com/content/sgf/2019/06/26/finding-n-th-instance-of-a-substring-within-a-string/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 19:36:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-characters-before-the-second-quot-quot-in-the-value/m-p/686180#M208174</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2020-09-23T19:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the characters before the second "-" in the value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-characters-before-the-second-quot-quot-in-the-value/m-p/686184#M208177</link>
      <description>&lt;P&gt;Program:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
	DROP	Second_Dash_Position;
	DROP	String_Length;
	LENGTH	With_Dashes	$35;
	INPUT	With_Dashes	$;
	Second_Dash_Position	=	FIND(With_Dashes, '-', (INDEX(With_Dashes, '-') + 1));
	String_Length			=	LENGTH(With_Dashes)	-	(LENGTH(With_Dashes)	-	Second_Dash_Position) - 1;
	IF	Second_Dash_Position	THEN
		Before_the_Dashes	=	SUBSTR(With_Dashes, 1, String_Length);
datalines;
happy-go-lucky
fleet-of-foot
down-in-the-mouth
woe-begone
fine-and-dandy
In-like-Flynn
The-more-the-merrier
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1600889354261.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49722i4414C8E3E95630AC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jimbarbour_0-1600889354261.png" alt="jimbarbour_0-1600889354261.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 19:30:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-characters-before-the-second-quot-quot-in-the-value/m-p/686184#M208177</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-23T19:30:22Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the characters before the second "-" in the value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-characters-before-the-second-quot-quot-in-the-value/m-p/686202#M208188</link>
      <description>&lt;P&gt;This should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;want = catx('-', scan(string, 1, '-'), scan(string, 2, '-') );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Sep 2020 20:10:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-characters-before-the-second-quot-quot-in-the-value/m-p/686202#M208188</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-09-23T20:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the characters before the second "-" in the value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-characters-before-the-second-quot-quot-in-the-value/m-p/686218#M208192</link>
      <description>&lt;P&gt;I really like your way of solving it! Thanks it's great &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 21:26:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-characters-before-the-second-quot-quot-in-the-value/m-p/686218#M208192</guid>
      <dc:creator>yichentian226</dc:creator>
      <dc:date>2020-09-23T21:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the characters before the second "-" in the value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-characters-before-the-second-quot-quot-in-the-value/m-p/686219#M208193</link>
      <description>&lt;P&gt;Thanks it's great! Very helpful&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 21:28:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-characters-before-the-second-quot-quot-in-the-value/m-p/686219#M208193</guid>
      <dc:creator>yichentian226</dc:creator>
      <dc:date>2020-09-23T21:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the characters before the second "-" in the value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-characters-before-the-second-quot-quot-in-the-value/m-p/686220#M208194</link>
      <description>&lt;P&gt;Thanks very much it worked!&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 21:28:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-characters-before-the-second-quot-quot-in-the-value/m-p/686220#M208194</guid>
      <dc:creator>yichentian226</dc:creator>
      <dc:date>2020-09-23T21:28:48Z</dc:date>
    </item>
  </channel>
</rss>

