<?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: extracting middle names  from a  variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/extracting-middle-names-from-a-variable/m-p/288041#M59350</link>
    <description>&lt;PRE&gt;
Here are two ways . One is CALL SCAN() , another is prxchange().



Data ds;
Infile datalines;
Input idno name&amp;amp;$30. Team $ strtwght endwght ;
call scan(name,1,p1,l1);
call scan(name,-1,p2,l2);
Middle_Name1=strip(substr(name,l1+1,p2-l1-1));

Middle_Name2=prxchange('s/^\w+|\w+$//',-1,strip(name));

drop p1 p2 l1 l2;
Datalines;
1331 Jason Schock paul Long   blue 187 172
1067 Kanoko john rav Nagasaka   green 135 122
1251 Richard roy granny Rose   blue 181 166
1192 Charlene tin Armstrong   yellow 152 139
1352 Bette Schock   green 156 137
1262 Yao Chen Garg   blue 196 180
1124 Adrienne Fink   green 156 142
;
run;

&lt;/PRE&gt;</description>
    <pubDate>Fri, 29 Jul 2016 05:54:05 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-07-29T05:54:05Z</dc:date>
    <item>
      <title>extracting middle names  from a  variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extracting-middle-names-from-a-variable/m-p/287941#M59298</link>
      <description>&lt;P&gt;&amp;nbsp;I have data like this.&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;&lt;P&gt;Data ds;&lt;BR /&gt;Infile datalines;&lt;BR /&gt;Input idno name&amp;amp;$30. Team $ strtwght endwght ;&lt;BR /&gt;Datalines;&lt;BR /&gt;1331 Jason Schock paul Long blue 187 172&lt;BR /&gt;1067 Kanoko john rav Nagasaka green 135 122&lt;BR /&gt;1251 Richard roy granny Rose blue 181 166&lt;BR /&gt;1192 Charlene tin Armstrong yellow 152 139&lt;BR /&gt;1352 Bette Schock green 156 137&lt;BR /&gt;1262 Yao Chen Garg blue 196 180&lt;BR /&gt;1124 Adrienne Fink green 156 142&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i nedd to get middle names&amp;nbsp;of name variable&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;the ouput should be like this;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;middlenames &amp;nbsp;only&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;SPAN&gt; Jason Schock paul Long ----------&amp;gt;&lt;/SPAN&gt;Schock paul(middle name)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Run;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2016 20:01:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extracting-middle-names-from-a-variable/m-p/287941#M59298</guid>
      <dc:creator>praveenkotte</dc:creator>
      <dc:date>2016-07-28T20:01:31Z</dc:date>
    </item>
    <item>
      <title>Re: extracting middle names  from a  variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extracting-middle-names-from-a-variable/m-p/287947#M59300</link>
      <description>&lt;P&gt;I would recommend looking into using the Regular Expression functions in SAS. Here is a paper with some examples to get you started&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.lexjansen.com/wuss/2004/data_warehousing/c_dwdb_taming_your_charac_p2.pdf" target="_blank"&gt;http://www.lexjansen.com/wuss/2004/data_warehousing/c_dwdb_taming_your_charac_p2.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck,&lt;/P&gt;
&lt;P&gt;Ahmed&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2016 20:29:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extracting-middle-names-from-a-variable/m-p/287947#M59300</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2016-07-28T20:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: extracting middle names  from a  variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extracting-middle-names-from-a-variable/m-p/287948#M59301</link>
      <description>&lt;P&gt;Will this help you?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
length middle $20;
   set ds;
   count = countw(name, ' ');
   middle = ' ';
   do i = 2 to count -1;
      word = scan(name, i, ' ', 'm');
      call catx(' ', middle, word);
   end;
   put name = middle =;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Jul 2016 20:31:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extracting-middle-names-from-a-variable/m-p/287948#M59301</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2016-07-28T20:31:32Z</dc:date>
    </item>
    <item>
      <title>Re: extracting middle names  from a  variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extracting-middle-names-from-a-variable/m-p/287949#M59302</link>
      <description>&lt;P&gt;If your data is regular enough&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Middlename=scan(Name,3);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That pulls the third word from the name variable.&lt;/P&gt;
&lt;P&gt;Your output example isn't really clear what your resulting data set would look like. I would recommend adding a new variable for the middle name.&lt;/P&gt;
&lt;P&gt;You might also then consider removing the middle name from the name field but it isn't clear if that was what you intend.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2016 20:32:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extracting-middle-names-from-a-variable/m-p/287949#M59302</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-07-28T20:32:07Z</dc:date>
    </item>
    <item>
      <title>Re: extracting middle names  from a  variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extracting-middle-names-from-a-variable/m-p/287969#M59313</link>
      <description>&lt;P&gt;&lt;FONT color="#FF0000"&gt;New Addition to the Earlier Solution&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
length middle $20;
   set ds;
   count = countw(name, ' ');
   middle = ' ';
   word1 = scan(name,1, ' ');
   word2 = scan(name, count, ' ');
   middle = transtrn(name, strip(word1), strip(' '));
   middle = transtrn(middle, strip(word2), strip(' '));

   put name = middle =;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2016 21:32:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extracting-middle-names-from-a-variable/m-p/287969#M59313</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2016-07-28T21:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: extracting middle names  from a  variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extracting-middle-names-from-a-variable/m-p/288041#M59350</link>
      <description>&lt;PRE&gt;
Here are two ways . One is CALL SCAN() , another is prxchange().



Data ds;
Infile datalines;
Input idno name&amp;amp;$30. Team $ strtwght endwght ;
call scan(name,1,p1,l1);
call scan(name,-1,p2,l2);
Middle_Name1=strip(substr(name,l1+1,p2-l1-1));

Middle_Name2=prxchange('s/^\w+|\w+$//',-1,strip(name));

drop p1 p2 l1 l2;
Datalines;
1331 Jason Schock paul Long   blue 187 172
1067 Kanoko john rav Nagasaka   green 135 122
1251 Richard roy granny Rose   blue 181 166
1192 Charlene tin Armstrong   yellow 152 139
1352 Bette Schock   green 156 137
1262 Yao Chen Garg   blue 196 180
1124 Adrienne Fink   green 156 142
;
run;

&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jul 2016 05:54:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extracting-middle-names-from-a-variable/m-p/288041#M59350</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-29T05:54:05Z</dc:date>
    </item>
  </channel>
</rss>

