<?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: How to extract numeric, character parts that are separated by spaces  from a whole string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-character-parts-that-are-separated-by/m-p/739697#M230910</link>
    <description>but it still giving problem, pr_names taking part of pr_qty in their column.</description>
    <pubDate>Fri, 07 May 2021 02:34:46 GMT</pubDate>
    <dc:creator>fsu1</dc:creator>
    <dc:date>2021-05-07T02:34:46Z</dc:date>
    <item>
      <title>How to extract numeric, character parts that are separated by spaces  from a whole string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-character-parts-that-are-separated-by/m-p/739690#M230907</link>
      <description>&lt;P&gt;data u;&lt;BR /&gt;input info $ 1 - 50;&lt;BR /&gt;cards;&lt;BR /&gt;101 pencils 37&lt;BR /&gt;102 parker pens 61&lt;BR /&gt;103 apple ipod shuffle &amp;amp; nano 08&lt;BR /&gt;104 dell studio laptop 03&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;I tried to write these code:&lt;/P&gt;&lt;P&gt;data check;&lt;BR /&gt;set u;&lt;BR /&gt;pr_id=input(scan(info,1,' '),3.);&lt;BR /&gt;pr_name=put(substr(info,2,' &amp;amp;'), &amp;amp; $30.);&lt;BR /&gt;pr_qty=input(scan(info,3,' '),3.);&lt;BR /&gt;drop info;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;It's not working&lt;/P&gt;</description>
      <pubDate>Fri, 07 May 2021 01:40:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-character-parts-that-are-separated-by/m-p/739690#M230907</guid>
      <dc:creator>fsu1</dc:creator>
      <dc:date>2021-05-07T01:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract numeric, character parts that are separated by spaces  from a whole string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-character-parts-that-are-separated-by/m-p/739693#M230908</link>
      <description>&lt;P&gt;You can use negative numbers in SCAN().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  part1 = scan(info,1,' ');
  part3 = scan(info,-1,' ');
  part2 = strip(substrn(info,length(part1)+2,length(info)-length(cats(part1,part3))-2));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It looks like only PART3 needs to be converted to a number. The other two should stay as strings.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  pr_qty=input(part3,32.);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 May 2021 01:59:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-character-parts-that-are-separated-by/m-p/739693#M230908</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-07T01:59:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract numeric, character parts that are separated by spaces  from a whole string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-character-parts-that-are-separated-by/m-p/739696#M230909</link>
      <description>&lt;P&gt;actually it has to be read like pr_id, pr_names and pr_qty so i write&amp;nbsp;&lt;/P&gt;&lt;P&gt;data check;&lt;BR /&gt;set u;&lt;BR /&gt;pr_id=input(scan(info,1,' '),3.);&lt;BR /&gt;pr_name=put(substr(info,5,25), $30.);&lt;BR /&gt;pr_qty=input(scan(info,-1,' '), 32.);&lt;BR /&gt;drop info;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 07 May 2021 02:17:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-character-parts-that-are-separated-by/m-p/739696#M230909</guid>
      <dc:creator>fsu1</dc:creator>
      <dc:date>2021-05-07T02:17:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract numeric, character parts that are separated by spaces  from a whole string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-character-parts-that-are-separated-by/m-p/739697#M230910</link>
      <description>but it still giving problem, pr_names taking part of pr_qty in their column.</description>
      <pubDate>Fri, 07 May 2021 02:34:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-character-parts-that-are-separated-by/m-p/739697#M230910</guid>
      <dc:creator>fsu1</dc:creator>
      <dc:date>2021-05-07T02:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract numeric, character parts that are separated by spaces  from a whole string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-character-parts-that-are-separated-by/m-p/739699#M230912</link>
      <description>&lt;P&gt;You have to make the start and length values used in SUBSTR() dynamic.&amp;nbsp; That is why it helps to first create the other two substrings so you can find their lengths.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to generate PR_ID as a number then do the same thing as I showed for PR_QTY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also look into the CALL SCAN() function as that allows you to generate positions. But the logic is more complicated than just make the two sub strings and then using LENGTH() on them.&lt;/P&gt;</description>
      <pubDate>Fri, 07 May 2021 02:44:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-character-parts-that-are-separated-by/m-p/739699#M230912</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-07T02:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract numeric, character parts that are separated by spaces  from a whole string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-character-parts-that-are-separated-by/m-p/739701#M230913</link>
      <description>&lt;P&gt;Here is another way.&amp;nbsp; Split it into ALL of the words and then put the middle ones back to together for your substring.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data check;
  set u;
  pr_id = input(scan(info,1,' '),32.);
  do index=2 to countw(info,' ')-1 ;
    pr_name = catx(' ',pr_name,scan(info,index,' '));
  end;
  pr_qty=input(scan(info,-1,' '),32.);
  drop index info;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 May 2021 02:46:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-character-parts-that-are-separated-by/m-p/739701#M230913</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-07T02:46:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract numeric, character parts that are separated by spaces  from a whole string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-character-parts-that-are-separated-by/m-p/739704#M230914</link>
      <description>&lt;P&gt;I have extend the data with another interesting product ending with a number and i switched from common char functions to a regular expression:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data u;
   input info $ 1 - 50;
   cards;
101 pencils 37
102 parker pens 61
103 apple ipod shuffle &amp;amp; nano 08
104 dell studio laptop 03
555 chanel no. 5 42
;

data want;
   set u;
   
   length 
      rx 8
      pr_id $ 3 /* no need for a numeric var, you won't use it in calculations */
      pr_name $ 30
      pr_qty 8
   ;
   
   retain rx;
   drop rx;
   
   if _n_ = 1 then do;
      rx = prxparse('/(\d+) (.+) (\d+)/');
   end;
   
   if prxmatch(rx, info) then do;
      pr_id = prxposn(rx, 1, info);
      pr_name = prxposn(rx, 2, info);
      pr_qty = input(prxposn(rx, 3, info), ?? 3.);
   end;   
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 May 2021 04:19:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-character-parts-that-are-separated-by/m-p/739704#M230914</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-05-07T04:19:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract numeric, character parts that are separated by spaces  from a whole string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-character-parts-that-are-separated-by/m-p/739715#M230921</link>
      <description>&lt;P&gt;Posting some code using call scan() like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;hinted could be used. Wouldn't have thought about it. Here one way how this could work (IF you've always got exactly three terms in your string).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input info $ 1 - 50;
  cards;
101 pencils 37
102 parker pens 61
103 apple ipod shuffle &amp;amp; nano 08
104 dell studio laptop 03
;

data want(drop=_:);
  set have;
  length term1 term2 term3 $20;
  call scan(info,1,_pos1,_len1,' ');
  call scan(info,-1,_pos3,_len3,' ');
  term1=substrn(info,_pos1,_len1);
  term2=substrn(info,_pos1+_len1,_pos3-_len1-1);
  term3=substrn(info,_pos3);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1620438698094.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59154iE7BFC283B6871EEB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1620438698094.png" alt="Patrick_0-1620438698094.png" /&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;</description>
      <pubDate>Sat, 08 May 2021 01:51:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-character-parts-that-are-separated-by/m-p/739715#M230921</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-05-08T01:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract numeric, character parts that are separated by spaces  from a whole string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-character-parts-that-are-separated-by/m-p/739763#M230939</link>
      <description>&lt;PRE&gt;data have;
  input info $ 1 - 50;
  cards;
101 pencils 37
102 parker pens 61
103 apple ipod shuffle &amp;amp; nano 08
104 dell studio laptop 03
;

data want;
 set have;
 term1=scan(info,1,' ');
 term2=prxchange('s/^\d+\s+|\d+$//',-1,strip(info));
 term3=scan(info,-1,' ');
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 May 2021 13:17:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-character-parts-that-are-separated-by/m-p/739763#M230939</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-05-07T13:17:10Z</dc:date>
    </item>
  </channel>
</rss>

