<?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: Help need in using scan function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-need-in-using-scan-function/m-p/723759#M224656</link>
    <description>&lt;P&gt;Thank you all for helping. My question was I have a variable 'value' in my data with as below. I need to split the value in to variables 'a and b'&amp;nbsp; as shown in output needed. For 'a' variable I am getting output I need. For 'b' i getting&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.32, 1.30)&amp;nbsp; &amp;nbsp; and&amp;nbsp;00.32, 10.30).&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;value&lt;/P&gt;
&lt;P&gt;5.00 (0.32, 1.30)&lt;BR /&gt;10.00 (00.32, 10.30)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output needed&lt;/P&gt;
&lt;P&gt;a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b&lt;/P&gt;
&lt;P&gt;5.00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(0.32, 1.30)&lt;/P&gt;
&lt;P&gt;10.00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(00.32, 10.30)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;code&amp;nbsp;&lt;/P&gt;
&lt;P&gt;a = strip(scan(value,1,'(' ));&lt;BR /&gt;b = strip(scan(value,2,'(' )); &lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Mar 2021 04:27:13 GMT</pubDate>
    <dc:creator>knveraraju91</dc:creator>
    <dc:date>2021-03-05T04:27:13Z</dc:date>
    <item>
      <title>Help need in using scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-need-in-using-scan-function/m-p/723741#M224648</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data aa;
input value $20.;
datalines;
5.00 (0.32, 1.30)
10.00 (00.32, 10.30)
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to split the &lt;FONT color="#FF6600"&gt;value&lt;/FONT&gt; variable in to two variables (&lt;FONT color="#FF6600"&gt;a&amp;nbsp; &amp;nbsp;and b&lt;/FONT&gt; ). I am able to extract first one using scan function. Please suggest which modifier i need to use in my code. Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;output need&lt;/P&gt;
&lt;P&gt;a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b&lt;/P&gt;
&lt;P&gt;5.00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(0.32, 1.30)&lt;/P&gt;
&lt;P&gt;10.00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(00.32, 10.30)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;my code;&lt;/P&gt;
&lt;P&gt;a=strip(scan(value,1,'('));&lt;/P&gt;
&lt;P&gt;b=&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 01:27:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-need-in-using-scan-function/m-p/723741#M224648</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2021-03-05T01:27:04Z</dc:date>
    </item>
    <item>
      <title>Re: Help need in using scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-need-in-using-scan-function/m-p/723748#M224650</link>
      <description>&lt;P&gt;Instead of a scan function, why not modify the INPUT statement to read in variables A and B directly?&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 02:25:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-need-in-using-scan-function/m-p/723748#M224650</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-03-05T02:25:04Z</dc:date>
    </item>
    <item>
      <title>Re: Help need in using scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-need-in-using-scan-function/m-p/723750#M224651</link>
      <description>&lt;P&gt;The delimiter to use, in your case, is '(' only:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;a = strip(scan(value,1,'(' ));
b = strip(scan(value,2,'(' ));  /* or =strip(scan(value,-1,'(' )); */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;meant:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data aa;
infile datalines dlm='(' truncover;
input a $ b $;
datalines;
5.00 (0.32, 1.30)
10.00 (00.32, 10.30)
;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 02:47:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-need-in-using-scan-function/m-p/723750#M224651</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-03-05T02:47:32Z</dc:date>
    </item>
    <item>
      <title>Re: Help need in using scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-need-in-using-scan-function/m-p/723756#M224654</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;meant:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data aa;
infile datalines dlm='(' truncover;
input a $ b $;
datalines;
5.00 (0.32, 1.30)
10.00 (00.32, 10.30)
;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's not quite what I meant, because I think the OP wanted to preserve the parentheses for variable B.&amp;nbsp; I had in mind using the "@" directive in the INPUT statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data aa;
input a :$5.0  @'(' +(-1)  b &amp;amp;$14. ;
put (_all_) (=);
datalines;
5.00 (0.32, 1.30)
10.00 (00.32, 10.30)
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also, to read B, there has to be an "&amp;amp;" in the informat to prevent a single space from terminating the value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edited addition:&amp;nbsp; And on further review I don't even need the "@" directive:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data aa;
input a :$5. b :&amp;amp;$14.;
put (_all_) (=);
datalines;
5.00 (0.32, 1.30)
10.00 (00.32, 10.30)
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Mar 2021 03:42:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-need-in-using-scan-function/m-p/723756#M224654</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-03-05T03:42:41Z</dc:date>
    </item>
    <item>
      <title>Re: Help need in using scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-need-in-using-scan-function/m-p/723759#M224656</link>
      <description>&lt;P&gt;Thank you all for helping. My question was I have a variable 'value' in my data with as below. I need to split the value in to variables 'a and b'&amp;nbsp; as shown in output needed. For 'a' variable I am getting output I need. For 'b' i getting&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.32, 1.30)&amp;nbsp; &amp;nbsp; and&amp;nbsp;00.32, 10.30).&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;value&lt;/P&gt;
&lt;P&gt;5.00 (0.32, 1.30)&lt;BR /&gt;10.00 (00.32, 10.30)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output needed&lt;/P&gt;
&lt;P&gt;a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b&lt;/P&gt;
&lt;P&gt;5.00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(0.32, 1.30)&lt;/P&gt;
&lt;P&gt;10.00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(00.32, 10.30)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;code&amp;nbsp;&lt;/P&gt;
&lt;P&gt;a = strip(scan(value,1,'(' ));&lt;BR /&gt;b = strip(scan(value,2,'(' )); &lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 04:27:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-need-in-using-scan-function/m-p/723759#M224656</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2021-03-05T04:27:13Z</dc:date>
    </item>
    <item>
      <title>Re: Help need in using scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-need-in-using-scan-function/m-p/723772#M224657</link>
      <description>&lt;P&gt;Your SCAN function is using "(" as the word separator, which means it is not included as part of the word value, which is a problem for variable b.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could prepend a '(' to b:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;b = cats('(',scan(value,2,'(' ));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Mar 2021 05:35:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-need-in-using-scan-function/m-p/723772#M224657</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-03-05T05:35:52Z</dc:date>
    </item>
    <item>
      <title>Re: Help need in using scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-need-in-using-scan-function/m-p/723778#M224660</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/68272"&gt;@knveraraju91&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data aa;
input value $20.;
datalines;
5.00 (0.32, 1.30)
10.00 (00.32, 10.30)
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to split the &lt;FONT color="#FF6600"&gt;value&lt;/FONT&gt; variable in to two variables (&lt;FONT color="#FF6600"&gt;a&amp;nbsp; &amp;nbsp;and b&lt;/FONT&gt; ). I am able to extract first one using scan function. Please suggest which modifier i need to use in my code. Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;output need&lt;/P&gt;
&lt;P&gt;a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b&lt;/P&gt;
&lt;P&gt;5.00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(0.32, 1.30)&lt;/P&gt;
&lt;P&gt;10.00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(00.32, 10.30)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;my code;&lt;/P&gt;
&lt;P&gt;a=strip(scan(value,1,'('));&lt;/P&gt;
&lt;P&gt;b=&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Thanks for providing data in usable form!&lt;/P&gt;
&lt;P&gt;Instead of using "scan", a regular expression could be used:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input value $20.;
datalines;
5.00 (0.32, 1.30)
10.00 (00.32, 10.30)
;

data want;
   set have;
   length a b $ 20;
   
   _rx = prxparse('/(.*\d) (.*)/');
   
   if prxmatch(_rx, value) then do;
      a = prxposn(_rx, 1, value);
      b = prxposn(_rx, 2, value);
   end;
   
   drop _rx;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Maybe the first part of the expression needs tweaking, depending on the other values you have.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 05:52:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-need-in-using-scan-function/m-p/723778#M224660</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-03-05T05:52:30Z</dc:date>
    </item>
    <item>
      <title>Re: Help need in using scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-need-in-using-scan-function/m-p/723849#M224700</link>
      <description>&lt;P&gt;You can also use the SUBSTR function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set aa;
a=scan(value,1,'(');
b=substr(value,length(a)+2);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This assumes that there's always &lt;EM&gt;one&lt;/EM&gt; blank between the two parts of the string. If the number of blanks may vary (0, 1, 2, ...), the LEFT function could compensate:&lt;/P&gt;
&lt;PRE&gt;b=&lt;FONT color="#FF0000"&gt;left(&lt;/FONT&gt;substr(value,length(a)+&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;)&lt;FONT color="#FF0000"&gt;)&lt;/FONT&gt;;&lt;/PRE&gt;
&lt;P&gt;(Note that &lt;FONT face="courier new,courier"&gt;strip(...)&lt;/FONT&gt; in the definition of &lt;FONT face="courier new,courier"&gt;a&lt;/FONT&gt; is redundant.)&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 12:06:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-need-in-using-scan-function/m-p/723849#M224700</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-03-05T12:06:09Z</dc:date>
    </item>
  </channel>
</rss>

