<?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: Using SCAN with consecutive delimiter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-SCAN-with-consecutive-delimiter/m-p/623812#M183712</link>
    <description>&lt;P&gt;Multiple consecutive delimiters are treated as one delimiter, so you need:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Version = scan(scan(Text, 4, '_'), 1, '@');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Depending on the paths you have, using a regular expression could yield more stable results. Assuming that the version consists of numbers only:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;VersionRx = prxchange('s/.*_(\d+)@/$1/', 1, Text);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 11 Feb 2020 12:02:34 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2020-02-11T12:02:34Z</dc:date>
    <item>
      <title>Using SCAN with consecutive delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SCAN-with-consecutive-delimiter/m-p/623811#M183711</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've got to tidy up our Calendars, and so I am reading in various bits of data. One of these is a simple 'ls' output from Unix of the PPM Calendar folder.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've noticed on occasion that the same calendar will exist a few times, but there's a version number I can extract that'll tell me which Calendar is the most recently utilised. Here's an example of the 'ls' output. I have highlighted the bit I need in bold.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;/opt/sas/platform/pm//work/calendar/CAL_END_AR______&lt;STRONG&gt;400&lt;/STRONG&gt;@username
/opt/sas/platform/pm//work/calendar/CAL_END_AR______&lt;STRONG&gt;401&lt;/STRONG&gt;@username
/opt/sas/platform/pm//work/calendar/CAL_END_AR______&lt;STRONG&gt;403&lt;/STRONG&gt;@username
/opt/sas/platform/pm//work/calendar/CAL_END_AR______&lt;STRONG&gt;404&lt;/STRONG&gt;@username&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to use SCAN to obtain the version number by first telling it to get the string after '_____', and the string before '@'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;x=scan(scan(Text,2,"_____"),1,"@");&lt;/PRE&gt;&lt;P&gt;SCAN is simply finding the first "_" rather than the concurrent "______". I've tried the 'o', 'm' and 'f' modifiers to no avail.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe SCAN isn't appropriate here, but does anyone know how I go about getting the 400, 401, 403, 404 etc?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know I could reverse the SCAN and find the '@' and then the '_____' but the principle remains - it'll only be finding the '_____' because it contains a single '_', so I am more interested in learning how to force SCAN to search for a consecutive delimiter, rather than haphazardly stumbling across a workaround.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 11:52:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SCAN-with-consecutive-delimiter/m-p/623811#M183711</guid>
      <dc:creator>_Dan_</dc:creator>
      <dc:date>2020-02-11T11:52:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using SCAN with consecutive delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SCAN-with-consecutive-delimiter/m-p/623812#M183712</link>
      <description>&lt;P&gt;Multiple consecutive delimiters are treated as one delimiter, so you need:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Version = scan(scan(Text, 4, '_'), 1, '@');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Depending on the paths you have, using a regular expression could yield more stable results. Assuming that the version consists of numbers only:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;VersionRx = prxchange('s/.*_(\d+)@/$1/', 1, Text);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Feb 2020 12:02:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SCAN-with-consecutive-delimiter/m-p/623812#M183712</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-02-11T12:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using SCAN with consecutive delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SCAN-with-consecutive-delimiter/m-p/623814#M183714</link>
      <description>&lt;P&gt;Thanks for your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first example, using SCAN with the assumption of 4 underscores won't work I'm afraid, as the strings are not always delimited with the same volume of underscores. Actual Calendar names have been changed, but the construct is the same.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;/opt/sas/platform/pm/work/calendar/PART1_PART2_____331@username
/opt/sas/platform/pm/work/calendar/PART1_PART2_PART3_____332@username
/opt/sas/platform/pm/work/calendar/PART1_PART2_25_____333@username&lt;/PRE&gt;&lt;P&gt;I did come across the prxchange answer elsewhere, but I may as well just reverse the SCAN using the 'b' modifier to get what I want. What I'm interested in is a way to tell SCAN that it must search for a concurrent volume of delimiters rather than a single one, but I suspect that is never the intended purpose, as a delimiter is naturally a single character.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 12:07:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SCAN-with-consecutive-delimiter/m-p/623814#M183714</guid>
      <dc:creator>_Dan_</dc:creator>
      <dc:date>2020-02-11T12:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using SCAN with consecutive delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SCAN-with-consecutive-delimiter/m-p/623821#M183717</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	var2 = compress(var1,,'DK');
	/*or*/
	var3 = prxchange('s/.*____(\d+)@.*/$1/',1,var1);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Feb 2020 12:50:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SCAN-with-consecutive-delimiter/m-p/623821#M183717</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-11T12:50:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using SCAN with consecutive delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SCAN-with-consecutive-delimiter/m-p/623824#M183718</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input var1:$80.;
	datalines;
/opt/sas/platform/pm//work/calendar/CAL_END_AR______400@username
/opt/sas/platform/pm//work/calendar/CAL_END_AR______401@username
/opt/sas/platform/pm//work/calendar/CAL_END_AR______403@username
/opt/sas/platform/pm//work/calendar/CAL_END_AR______404@username
;
run;

data want;
	set have;
	var4 = scan(scan(tranwrd(var1,'______','*'),2,'*'),1,'@');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Feb 2020 12:57:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SCAN-with-consecutive-delimiter/m-p/623824#M183718</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-11T12:57:11Z</dc:date>
    </item>
    <item>
      <title>Re: Using SCAN with consecutive delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SCAN-with-consecutive-delimiter/m-p/623831#M183719</link>
      <description>&lt;P&gt;Perhaps this isn't exceedingly ugly:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   var2 = scan(substr(var1, index(var1, '____')), 1, '@');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Feb 2020 13:29:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SCAN-with-consecutive-delimiter/m-p/623831#M183719</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-02-11T13:29:51Z</dc:date>
    </item>
    <item>
      <title>Re: Using SCAN with consecutive delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SCAN-with-consecutive-delimiter/m-p/623846#M183721</link>
      <description>&lt;P&gt;SCAN() uses ANY of the characters as a delimiter. So listing the same character one or ten times does not make a difference.&lt;/P&gt;
&lt;P&gt;But it looks like you pattern could be parsed by SCAN() if you just search from the words from the end instead of the beginning.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x=scan(Text,-2,'@_');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Word number -1 will be username and word number -2 will by 400.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 14:13:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SCAN-with-consecutive-delimiter/m-p/623846#M183721</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-11T14:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using SCAN with consecutive delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SCAN-with-consecutive-delimiter/m-p/623930#M183732</link>
      <description>&lt;P&gt;using regular expressions would be my recommendation. &amp;nbsp;&lt;/P&gt;&lt;P&gt;But if you want SAS to find consecutive delimiters here is a highly inefficient method to do what you are asking for&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA A;
B ='/opt/sas/platform/pm//work/calendar/CAL_END_AR______400@username';
DO I = 1 TO count(b,'_');
C =         SCAN(B,I,'_');
D =         SCAN(B,I,'_','M');
IF C NE D THEN DO;
  WANT=SCAN(C,1,'@');
  PUT WANT=;
  STOP;
END;
END;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 18:43:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SCAN-with-consecutive-delimiter/m-p/623930#M183732</guid>
      <dc:creator>fdsaaaa</dc:creator>
      <dc:date>2020-02-11T18:43:29Z</dc:date>
    </item>
  </channel>
</rss>

