<?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 SCAN function? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-SCAN-function/m-p/590170#M168872</link>
    <description>&lt;P&gt;Ooops..&amp;nbsp;&amp;nbsp; In my original code (not the 'pseudo code' I posted here) I had REALFLD1 and REALFLD2 reversed as they were close in spelling.&amp;nbsp; Sorry for wasting everyone's brain time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 19 Sep 2019 19:35:26 GMT</pubDate>
    <dc:creator>TimH</dc:creator>
    <dc:date>2019-09-19T19:35:26Z</dc:date>
    <item>
      <title>Problem with SCAN function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-SCAN-function/m-p/590122#M168861</link>
      <description>&lt;P&gt;I have fields which contain either "String1"&amp;nbsp;&amp;nbsp; or they contain "String1\String2"&amp;nbsp; with "\" as the delimiter between the two strings.&lt;BR /&gt;&lt;BR /&gt;I input the field with INPUT @col&amp;nbsp; WORKFLD $20.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I then have this code (following the example in the documentation for getting the first and last word in the string&lt;/P&gt;
&lt;P&gt;REALFLD1 = SCAN(WORKFLD,1,'\'); &lt;/P&gt;
&lt;P&gt;IF INDEX(WORKFLID,'\') &amp;gt; 0 &lt;BR /&gt;THEN &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; REALFLD2 = SCAN(WORKFLD,-1,'\');&lt;BR /&gt;&lt;BR /&gt;It seems to work "backward"&amp;nbsp; - when WORKFLD contains "OPSYS\KNMACTH"&amp;nbsp;&amp;nbsp; the results are REALFLD1 = KNMACTH and REALFLD2 = OPSYS&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;If I switch the '1' and the '-1' I get what I want but I'm not sure why it is working this way...&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 17:15:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-SCAN-function/m-p/590122#M168861</guid>
      <dc:creator>TimH</dc:creator>
      <dc:date>2019-09-19T17:15:34Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SCAN function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-SCAN-function/m-p/590127#M168862</link>
      <description>&lt;P&gt;If you want first and last word another column just use catx with scan&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;catx('-',scan(col1,1,'/'),scan(col1,-1,'/'))&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 17:23:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-SCAN-function/m-p/590127#M168862</guid>
      <dc:creator>SwagatPatil</dc:creator>
      <dc:date>2019-09-19T17:23:22Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SCAN function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-SCAN-function/m-p/590130#M168863</link>
      <description>&lt;P&gt;No, I want the two values to be in two separate fields, not concatenated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note the slash is '\' and not this '/'&amp;nbsp; (which is one of the default delimiters for the function)&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 17:30:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-SCAN-function/m-p/590130#M168863</guid>
      <dc:creator>TimH</dc:creator>
      <dc:date>2019-09-19T17:30:34Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SCAN function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-SCAN-function/m-p/590141#M168865</link>
      <description>&lt;P&gt;Works fine for me.&lt;/P&gt;
&lt;PRE&gt;511   data test;
512     have= "OPSYS\KNMACTH"  ;
513     first=scan(have,1,'\');
514     last=scan(have,-1,'\');
515     put (_all_) (=);
516   run;

have=OPSYS\KNMACTH first=OPSYS last=KNMACTH
&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Sep 2019 17:51:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-SCAN-function/m-p/590141#M168865</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-19T17:51:23Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SCAN function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-SCAN-function/m-p/590142#M168866</link>
      <description>&lt;P&gt;When I run your code,&amp;nbsp;after correcting the WORKFLID to WORKFLD with&lt;/P&gt;
&lt;PRE&gt;237  data junk;
238     WORKFLD="OPSYS\KNMACTH";
239     REALFLD1 = SCAN(WORKFLD,1,'\');
240     IF INDEX(WORKFLD,'\') &amp;gt; 0 THEN
241      REALFLD2 = SCAN(WORKFLD,-1,'\');
242     put _all_;
243  run;

WORKFLD=OPSYS\KNMACTH REALFLD1=OPSYS REALFLD2=KNMACTH _ERROR_=0 _N_=1
&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;I do not get your stated result.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;Since you likely did not paste code from your actual program then it is likely that you either 1) reversed the names of the REALFLD variables OR used the 1 and -1 in the incorrect code location.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 17:53:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-SCAN-function/m-p/590142#M168866</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-09-19T17:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SCAN function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-SCAN-function/m-p/590170#M168872</link>
      <description>&lt;P&gt;Ooops..&amp;nbsp;&amp;nbsp; In my original code (not the 'pseudo code' I posted here) I had REALFLD1 and REALFLD2 reversed as they were close in spelling.&amp;nbsp; Sorry for wasting everyone's brain time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 19:35:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-SCAN-function/m-p/590170#M168872</guid>
      <dc:creator>TimH</dc:creator>
      <dc:date>2019-09-19T19:35:26Z</dc:date>
    </item>
  </channel>
</rss>

