<?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 1st word to nth word from a string variable and output as a string variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-1st-word-to-nth-word-from-a-string-variable-and/m-p/359637#M84582</link>
    <description>&lt;P&gt;HoHo. You are doing this under IML code. You really want do this via IML ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let XTEMPLIST  =  BA EN CO CA SV IN UT TRA;
 
  proc iml;
    s="&amp;amp;xtemplist";
    delims = ' ';
    n = countw(s, delims);
    xtemplist1 = scan(s, 1:3, delims);
    xtemplist2 = scan(s, 4:n, delims);
    print xtemplist1;
    call symput("t",rowcat(xtemplist1+' '));
    call symput("t1",rowcat(xtemplist2+' '));
  quit;
%put &amp;amp;t;  
%put &amp;amp;t1;  &lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 18 May 2017 13:05:03 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2017-05-18T13:05:03Z</dc:date>
    <item>
      <title>How to extract 1st word to nth word from a string variable and output as a string variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-1st-word-to-nth-word-from-a-string-variable-and/m-p/359421#M84524</link>
      <description>&lt;P&gt;Dear Experts&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let XTEMPLIST&amp;nbsp; =&amp;nbsp; BA EN CO CA SV IN UT TRA;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; proc iml;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; s="&amp;amp;xtemplist";&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; delims = ' ';&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; n = countw(s, delims);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; xtemplist1 = scan(s, 1:3, delims);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; xtemplist2 = scan(s, 4:n, delims);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print xtemplist1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symput("t",xtemplist1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symput("t1",xtemplist2);&lt;BR /&gt;&amp;nbsp; quit;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;t;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;t1;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&amp;gt;&amp;gt; t--&amp;gt;only CO is displayed. How to get BA EN CO?&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;t1-&amp;gt;&amp;gt;TRA is displayed. How to get CA SV IN UT TRA?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help&lt;/P&gt;
&lt;P&gt;:LL&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2017 16:31:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-1st-word-to-nth-word-from-a-string-variable-and/m-p/359421#M84524</guid>
      <dc:creator>CheerfulChu</dc:creator>
      <dc:date>2017-05-17T16:31:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract 1st word to nth word from a string variable and output as a string variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-1st-word-to-nth-word-from-a-string-variable-and/m-p/359428#M84525</link>
      <description>&lt;P&gt;Here's a way that keeps all the processing under the control of macro language.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let XTEMPLIST&amp;nbsp; =&amp;nbsp; BA EN CO CA SV IN UT TRA;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro split (n=3);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%GLOBAL XTEMPLIST1 XTEMPLIST2;&lt;/P&gt;
&lt;P&gt;%let xtemplist1=;&lt;/P&gt;
&lt;P&gt;%local i;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%do i=1 %to &amp;amp;n;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; %let xtemplist1 = &amp;amp;xtemplist1 %scan(&amp;amp;xtemplist, &amp;amp;i);&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let xtemplist2 = %substr(xtemplist, %length(&amp;amp;xtemplist1) + 1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mend split;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%split (n=3)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because of the %do loop, you will need to define a macro.&amp;nbsp; On the other hand, you gain the advantage of being able to control how many words are selected into the first variable.&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2017 16:47:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-1st-word-to-nth-word-from-a-string-variable-and/m-p/359428#M84525</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-05-17T16:47:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract 1st word to nth word from a string variable and output as a string variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-1st-word-to-nth-word-from-a-string-variable-and/m-p/359637#M84582</link>
      <description>&lt;P&gt;HoHo. You are doing this under IML code. You really want do this via IML ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let XTEMPLIST  =  BA EN CO CA SV IN UT TRA;
 
  proc iml;
    s="&amp;amp;xtemplist";
    delims = ' ';
    n = countw(s, delims);
    xtemplist1 = scan(s, 1:3, delims);
    xtemplist2 = scan(s, 4:n, delims);
    print xtemplist1;
    call symput("t",rowcat(xtemplist1+' '));
    call symput("t1",rowcat(xtemplist2+' '));
  quit;
%put &amp;amp;t;  
%put &amp;amp;t1;  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 May 2017 13:05:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-1st-word-to-nth-word-from-a-string-variable-and/m-p/359637#M84582</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-05-18T13:05:03Z</dc:date>
    </item>
  </channel>
</rss>

