<?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: Scan function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Scan-function/m-p/928948#M365523</link>
    <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;My question was what happens if there are multiple delimiters? Then which delimiter is the reference? The first one from left side?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 4&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Try it and see.&lt;/P&gt;</description>
    <pubDate>Sun, 19 May 2024 10:33:22 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2024-05-19T10:33:22Z</dc:date>
    <item>
      <title>Scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scan-function/m-p/928940#M365517</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a string that have 3 words with two commas between them.&lt;/P&gt;
&lt;P&gt;I want to calculated 3 fields- continent, city,country.&lt;/P&gt;
&lt;P&gt;Can anyone explain why&amp;nbsp;&amp;nbsp;City=scan(X,-2,",");&amp;nbsp; result with&amp;nbsp; city?&lt;/P&gt;
&lt;P&gt;In this case there are 2 commas, to which comma this code refer to? to first or second?&lt;/P&gt;
&lt;P&gt;As I understand since -2 is negative then it search for the word in right side of the comma?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input X $20.;
cards;
EU,Athens,Greece
Asia,Beijing,China
;
run;
data want;
set have;
continent=scan(X,1,",");/**EU**/
City=scan(X,-2,",");/**Athens**/
Country=scan(X,-1,",");/**Greece**/
Run;&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;</description>
      <pubDate>Sun, 19 May 2024 08:52:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scan-function/m-p/928940#M365517</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-05-19T08:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: Scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scan-function/m-p/928942#M365518</link>
      <description>&lt;P&gt;You don't have the doc?&lt;BR /&gt;It's on www as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL class="xisDoc-listUnordered"&gt;
&lt;LI class="xisDoc-item"&gt;If&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;count&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;is positive, SCAN counts words from left to right in the character string.&lt;/LI&gt;
&lt;LI class="xisDoc-item"&gt;If&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;count&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;is negative, SCAN counts words from right to left in the character string.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Functions and CALL Routines&lt;BR /&gt;SCAN Function&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0jshdjy2z9zdzn1h7k90u99lyq6.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0jshdjy2z9zdzn1h7k90u99lyq6.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sun, 19 May 2024 09:20:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scan-function/m-p/928942#M365518</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2024-05-19T09:20:46Z</dc:date>
    </item>
    <item>
      <title>Re: Scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scan-function/m-p/928943#M365519</link>
      <description>&lt;P&gt;My question was what happens if there are multiple delimiters? Then which delimiter is the reference? The first one from left side?&lt;/P&gt;</description>
      <pubDate>Sun, 19 May 2024 09:28:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scan-function/m-p/928943#M365519</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-05-19T09:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: Scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scan-function/m-p/928944#M365520</link>
      <description>&lt;P&gt;If there are multiple delimiters, they are all reduced to a common delimiter (also in the strings to scan) and then the scan is performed on that common delimiter. I don't know if that's really how it happens in the background (probably not), but that's how to think about it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input X $20.;
cards;
EU,Athens#Greece
Asia#Beijing,China
;
run;
data want;
set have;
continent = scan(X, 1,",#");/**EU**/
City      = scan(X,-2,",#");/**Athens**/
Country   = scan(X,-1,",#");/**Greece**/
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sun, 19 May 2024 09:37:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scan-function/m-p/928944#M365520</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2024-05-19T09:37:23Z</dc:date>
    </item>
    <item>
      <title>Re: Scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scan-function/m-p/928945#M365521</link>
      <description>" if there are multiple delimiters?"&lt;BR /&gt;Then SAS will take them as ONE delimiter. &lt;BR /&gt;Except you specify the fourth argument ('m') in SCAN() :&lt;BR /&gt;continent=scan(X,1,","  , 'm');&lt;BR /&gt;&lt;BR /&gt;You could make seveal examples to see how they are different.</description>
      <pubDate>Sun, 19 May 2024 09:38:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scan-function/m-p/928945#M365521</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-05-19T09:38:02Z</dc:date>
    </item>
    <item>
      <title>Re: Scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scan-function/m-p/928946#M365522</link>
      <description>&lt;P&gt;Ah oké, that's what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;means with multiple delimiters.&lt;/P&gt;
&lt;P&gt;Indeed ... answer provided by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;in that case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the doc about that m (or M) modifier:&lt;/P&gt;
&lt;DIV class="xisDoc-refBlock"&gt;
&lt;DIV class="xisDoc-syntax"&gt;
&lt;DIV class="xisDoc-syntaxDescription"&gt;
&lt;DIV class="xisDoc-optionalArgGroup"&gt;
&lt;DIV id="n125492vxo9uxmn19esm1g0eezji" class="xisDoc-argDescriptionPair"&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;SECTION class="xisDoc-tableWrap"&gt;
&lt;TABLE class="xisDoc-listValueDescription"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="xisDoc-value"&gt;m or M&lt;/TD&gt;
&lt;TD class="xisDoc-valueDescription"&gt;specifies that multiple consecutive delimiters, and delimiters at the beginning or end of the &lt;EM class="xisDoc-userSuppliedValue"&gt;string&lt;/EM&gt; argument, refer to words that have a length of zero. If the M modifier is not specified, then multiple consecutive delimiters are treated as one delimiter, and delimiters at the beginning or end of the &lt;EM class="xisDoc-userSuppliedValue"&gt;string&lt;/EM&gt; argument are ignored.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/SECTION&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;BR /&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sun, 19 May 2024 09:41:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scan-function/m-p/928946#M365522</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2024-05-19T09:41:45Z</dc:date>
    </item>
    <item>
      <title>Re: Scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scan-function/m-p/928948#M365523</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;My question was what happens if there are multiple delimiters? Then which delimiter is the reference? The first one from left side?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 4&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Try it and see.&lt;/P&gt;</description>
      <pubDate>Sun, 19 May 2024 10:33:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scan-function/m-p/928948#M365523</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-05-19T10:33:22Z</dc:date>
    </item>
    <item>
      <title>Re: Scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scan-function/m-p/928953#M365527</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;My question was what happens if there are multiple delimiters? Then which delimiter is the reference? The first one from left side?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It is not referencing the delimiters.&amp;nbsp; It is referencing the words that are formed by splitting the string at the delimiters.&amp;nbsp; Consider a string with 5 words.&amp;nbsp; Here are some example 5 word strings when the comma is the delimiter.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;one,two,three,four,five
This sentence,is divided,into,five,parts&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can either count from left to right but using positive indexes. Or count from right to left by using negative indexes.&lt;/P&gt;
&lt;PRE&gt;Word   Positive  Negative
one     1       -5
two     2       -4
three   3       -3
four    4       -2
five    5       -1&lt;/PRE&gt;</description>
      <pubDate>Sun, 19 May 2024 16:32:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scan-function/m-p/928953#M365527</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-05-19T16:32:11Z</dc:date>
    </item>
  </channel>
</rss>

