<?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 I want to extract 3rd word from each line using character function other than scan function. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477005#M122782</link>
    <description>&lt;P&gt;Hai All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data a;&lt;BR /&gt;input details &amp;amp;:$50.;&lt;BR /&gt;cards;&lt;BR /&gt;my name is parthasaradhi&lt;BR /&gt;i am from dowlaiswaram&lt;BR /&gt;it is nearer to rajahmundry&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to extract 3rd word from each line using character function other than scan function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;new variable values is like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is&lt;/P&gt;&lt;P&gt;from&lt;/P&gt;&lt;P&gt;nearer&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in Advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 11 Jul 2018 08:41:44 GMT</pubDate>
    <dc:creator>Parthach</dc:creator>
    <dc:date>2018-07-11T08:41:44Z</dc:date>
    <item>
      <title>I want to extract 3rd word from each line using character function other than scan function.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477005#M122782</link>
      <description>&lt;P&gt;Hai All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data a;&lt;BR /&gt;input details &amp;amp;:$50.;&lt;BR /&gt;cards;&lt;BR /&gt;my name is parthasaradhi&lt;BR /&gt;i am from dowlaiswaram&lt;BR /&gt;it is nearer to rajahmundry&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to extract 3rd word from each line using character function other than scan function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;new variable values is like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is&lt;/P&gt;&lt;P&gt;from&lt;/P&gt;&lt;P&gt;nearer&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in Advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jul 2018 08:41:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477005#M122782</guid>
      <dc:creator>Parthach</dc:creator>
      <dc:date>2018-07-11T08:41:44Z</dc:date>
    </item>
    <item>
      <title>Re: I want to extract 3rd word from each line using character function other than scan function.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477007#M122783</link>
      <description>&lt;P&gt;"I want to extract 3rd word from each line using character function other than scan function."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And next you try to run without using your feet?&lt;/P&gt;
&lt;P&gt;The scan() function is THE tool for this, use it.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jul 2018 08:45:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477007#M122783</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-11T08:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: I want to extract 3rd word from each line using character function other than scan function.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477008#M122784</link>
      <description>&lt;P&gt;If this is actually some kind of homework, then &lt;EM&gt;you&lt;/EM&gt; are supposed to solve it, not &lt;EM&gt;we&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;Hints:&lt;/P&gt;
&lt;P&gt;Use a loop with the findc() function to find the second occurence of a blank. Then find the next occurence of a blank (keep in mind that all character variables are padded with blanks), and use substr() with the positions you determined.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jul 2018 09:04:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477008#M122784</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-11T09:04:52Z</dc:date>
    </item>
    <item>
      <title>Re: I want to extract 3rd word from each line using character function other than scan function.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477009#M122785</link>
      <description>&lt;P&gt;As you do not want to use SCAN function, you can loop the line character by character, using SUBSTR function,&lt;/P&gt;
&lt;P&gt;check for a space (or any other delimiter), count it and select all characters between the 2nd and the 3rd space/delimiter.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jul 2018 09:05:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477009#M122785</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-07-11T09:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: I want to extract 3rd word from each line using character function other than scan function.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477011#M122787</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Well done on presenting your input data in the form of a data step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a reason you want to avoid using the &lt;FONT face="courier new,courier"&gt;scan()&lt;/FONT&gt; function, e.g., this is a homework exercise, curiosity, you want to practice using other character manipulation functions, your boss said so (in which case ask your boss why), etc.?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As has already been indicated by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, each word is separated by spaces, so &lt;FONT face="courier new,courier"&gt;scan()&lt;/FONT&gt; would ordinarily be the way to go, so giving us the reason why you don't want to use &lt;FONT face="courier new,courier"&gt;scan()&lt;/FONT&gt; might help us understand your thinking for asking, so that we can advise accordingly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jul 2018 09:10:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477011#M122787</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2018-07-11T09:10:26Z</dc:date>
    </item>
    <item>
      <title>Re: I want to extract 3rd word from each line using character function other than scan function.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477012#M122788</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A less serious, but potentially still valid response, is if you're not allowed to use the &lt;FONT face="courier new,courier"&gt;scan()&lt;/FONT&gt; function, then how about using the &lt;FONT face="courier new,courier"&gt;%scan()&lt;/FONT&gt; function?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT: Or even the &lt;FONT face="courier new,courier"&gt;scanq()&lt;/FONT&gt; function?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jul 2018 09:21:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477012#M122788</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2018-07-11T09:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: I want to extract 3rd word from each line using character function other than scan function.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477019#M122792</link>
      <description>&lt;P&gt;Many ways to skin that cat. I would suggest using PRX (Pearl Regular Expressions), as they are worth learning:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set a;
  prxid=prxparse('/^\s*\S+\s+\S+\s+(\S+)/');
  drop prxid;
  length thirdword $10;
  if prxmatch(prxid,details) then
    thirdword=prxposn(prxid,1,details);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;A short explanation:&lt;/P&gt;&lt;P&gt;^ Means beginning of string&lt;/P&gt;&lt;P&gt;\s* Means zero or more blanks (or other whitespace characters, such as tabs)&lt;/P&gt;&lt;P&gt;\S+ Means one or more non-blanks (non-whitespace)&lt;/P&gt;&lt;P&gt;\s+ Means one or more blanks&lt;/P&gt;&lt;P&gt;(\S+) puts the third occurence of one or more non-blanks in a capture buffer (the one and only in this case).&amp;nbsp;&lt;/P&gt;&lt;P&gt;PRXPOSN then retrieves the contents of the first capture buffer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But sometimes you need to do stuff where it would be very handy if the variable you wanted to parse was in a file, so that you could use INPUT statements to parse it. In that case you do not have to write the whole dataset to a file and then read it, you can just use the fact that the _INFILE_ variable contains the input buffer, and it can be written to:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile sasautos(verify.sas) ;
  if _N_= 1 then input @@;
  set a;
  _infile_=details;
  input @1 thirdword $ thirdword $ thirdword $ @@ ;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I used SASAUTOS(VERIFY.SAS) as the infile, as the file must exist, and this macro seems to exist on most SAS installations.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jul 2018 10:08:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477019#M122792</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-07-11T10:08:08Z</dc:date>
    </item>
    <item>
      <title>Re: I want to extract 3rd word from each line using character function other than scan function.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477022#M122795</link>
      <description>Hai Mr. Bremser,&lt;BR /&gt;I am trying to do it but how to find out second occurrence of blank.&lt;BR /&gt;&lt;BR /&gt;data b;&lt;BR /&gt;set a;&lt;BR /&gt;info=findc(details," ");&lt;BR /&gt;run;&lt;BR /&gt;it is showing first occurrence of blank but not second.&lt;BR /&gt;Help me&lt;BR /&gt;.&lt;BR /&gt;Thanks</description>
      <pubDate>Wed, 11 Jul 2018 10:21:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477022#M122795</guid>
      <dc:creator>Parthach</dc:creator>
      <dc:date>2018-07-11T10:21:30Z</dc:date>
    </item>
    <item>
      <title>Re: I want to extract 3rd word from each line using character function other than scan function.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477030#M122799</link>
      <description>&lt;P&gt;As I said, you need to do a loop to find the second occurence. One feature of findc is that you can supply a start position for the search.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;start = findc(details,' ');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will find the first occurence.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;start = findc(details,' ',start+1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will find the next occurence after that. If you repeat that until you get the nth occurence (2 if you want to find the 3rd word), you have the start for your substring. How you find the end should be quite obvious now. Note that the third parameter for substr() has to be a length, not a position, so you need to do a little calculation there.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jul 2018 10:51:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477030#M122799</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-11T10:51:21Z</dc:date>
    </item>
    <item>
      <title>Re: I want to extract 3rd word from each line using character function other than scan function.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477053#M122806</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 

data a;
input details &amp;amp;:$50.;
details=compbl(details);
n=0;
do i=1 to length(details);
 if char(details,i)=' ' then do;n+1;if n=2 then s=i;if n=3 then e=i;end;
end;
want=substr(details,s,e-s);
cards;
my name is parthasaradhi
i am from dowlaiswaram
it is nearer to rajahmundry
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Jul 2018 12:43:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477053#M122806</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-07-11T12:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: I want to extract 3rd word from each line using character function other than scan function.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477123#M122827</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input details &amp;amp; $50.;
cards;
my name is parthasaradhi
i am from dowlaiswaram
it is nearer to rajahmundry
;
run;

data output;
set a;
k=substr(details,anyspace(details)+1);
k1=substr(k,anyspace(strip(k))+1);
want=substr(k1,1,anyspace(k1));
drop k:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Jul 2018 15:21:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477123#M122827</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-11T15:21:04Z</dc:date>
    </item>
    <item>
      <title>Re: I want to extract 3rd word from each line using character function other than scan function.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477543#M123012</link>
      <description>Hai Kurt Bremser,&lt;BR /&gt;Thanks for your suggestions.&lt;BR /&gt;here is the code:&lt;BR /&gt;&lt;BR /&gt;/*without scan function*/&lt;BR /&gt;data c;&lt;BR /&gt;set a;&lt;BR /&gt;info=findc(details,"",4+1);&lt;BR /&gt;infon=findc(details,"",9+1);&lt;BR /&gt;ext=substr(details,info,infon-info);&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Finally i got it.&lt;BR /&gt;Thanks for the support.&lt;BR /&gt;&lt;BR /&gt;Partha.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 12 Jul 2018 15:23:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-want-to-extract-3rd-word-from-each-line-using-character/m-p/477543#M123012</guid>
      <dc:creator>Parthach</dc:creator>
      <dc:date>2018-07-12T15:23:34Z</dc:date>
    </item>
  </channel>
</rss>

