<?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: Parse text String into different Variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Parse-text-String-into-different-Variables/m-p/16140#M2235</link>
    <description>You could try this also:&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
&lt;BR /&gt;
S='AAAA AAAA AAAA AAA AAAAA AAAAAA, AAAAA AAAA AAAAAAAAAAAAA BBB BBBBB BBBBB BBBBB BBBBBB BBBBB BBBBBBB BBBBBBBBBBBB CCCCCCC CCCCC CCCCCCC CCCCCCC CCCCC CCCC CCCCCCCCCC DDDD DDDDD DDDD DDDDDDD DDDDD DDDDDDDD DDDD DDDDD DDDDDD DDDDD DDDD';&lt;BR /&gt;
&lt;BR /&gt;
I1=1*55+index(substr(S,55),' ')-1; /* 1st split starting at 55 */&lt;BR /&gt;
I2=2*55+index(substr(S,2*55),' ')-1; /* 2nd split starting at 2x55 */&lt;BR /&gt;
I3=3*55+index(substr(S,3*55),' ')-1; /* 3rd split starting at 3x55 */&lt;BR /&gt;
VAR1=substr(S,1,I1); &lt;BR /&gt;
VAR2=substr(S,I1,I2-I1);&lt;BR /&gt;
VAR3=substr(S,I2,I3-I2);&lt;BR /&gt;
VAR4=substr(S,I3);&lt;BR /&gt;
&lt;BR /&gt;
/* result */&lt;BR /&gt;
put VAR1=;&lt;BR /&gt;
put VAR2=;&lt;BR /&gt;
put VAR3=;&lt;BR /&gt;
put VAR4=;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Greetings from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos at &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
    <pubDate>Wed, 08 Apr 2009 11:21:02 GMT</pubDate>
    <dc:creator>DanielSantos</dc:creator>
    <dc:date>2009-04-08T11:21:02Z</dc:date>
    <item>
      <title>Parse text String into different Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-text-String-into-different-Variables/m-p/16137#M2232</link>
      <description>I have a variable( around 250 char long) containing text. I wanted to break this text into 4 different variables say each containing around 60 characters. As I'll be printing this text on my report I wanted to break the text exactly between words( something like looking for a first space between letters 55-65, break the text and put it into Variable1 and do the same for rest of the text). I tried to do this with the help of index and scan functions and failed. &lt;BR /&gt;
&lt;BR /&gt;
Any help is greatly appreciated.&lt;BR /&gt;
&lt;BR /&gt;
Eddie</description>
      <pubDate>Tue, 07 Apr 2009 14:26:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-text-String-into-different-Variables/m-p/16137#M2232</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-04-07T14:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: Parse text String into different Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-text-String-into-different-Variables/m-p/16138#M2233</link>
      <description>Yes, the INDEX and SUBSTR functions will identify the offset where the previous or next blank begins, so you can assign your new SAS variables.  Share what code you have already attempted to use for forum subscriber feedback/comment.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 07 Apr 2009 14:53:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-text-String-into-different-Variables/m-p/16138#M2233</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-04-07T14:53:14Z</dc:date>
    </item>
    <item>
      <title>Re: Parse text String into different Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-text-String-into-different-Variables/m-p/16139#M2234</link>
      <description>This is just a quick hack - has not been testet for all cases, but perhaps you can use it as an starting point for your own code.&lt;BR /&gt;
[pre]&lt;BR /&gt;
data longsmall(drop=txt t i text x);&lt;BR /&gt;
  length txt t $60;&lt;BR /&gt;
  array smalltxt(6) $60.;&lt;BR /&gt;
  text="I have a variable (around 250 char long) containing text. I wanted to break this text into 4 different variables say each containing around 60 characters. As I ll be printing this text on my report I wanted to break the text exactly between words";&lt;BR /&gt;
  do until (t=" ");&lt;BR /&gt;
    i+1;&lt;BR /&gt;
    t = scan(text,i," ");&lt;BR /&gt;
    if length(catx(" ",txt,t)) &amp;lt; 50 then&lt;BR /&gt;
     txt=catx('%20',txt,t); &lt;BR /&gt;
    else &lt;BR /&gt;
     do;&lt;BR /&gt;
      x+1;&lt;BR /&gt;
      put x= txt;&lt;BR /&gt;
      smalltxt(x)=txt;&lt;BR /&gt;
      txt = t; &lt;BR /&gt;
     end;&lt;BR /&gt;
  end;&lt;BR /&gt;
  x+1;&lt;BR /&gt;
  put x= txt;&lt;BR /&gt;
  smalltxt(x)=txt;   &lt;BR /&gt;
run;&lt;BR /&gt;
 &lt;BR /&gt;
Message was edited by: Geniz&lt;BR /&gt;
 &lt;BR /&gt;
replace %20 in the code with a normal space. The forum cuts my text when I use a space at this place - very strange???</description>
      <pubDate>Tue, 07 Apr 2009 23:34:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-text-String-into-different-Variables/m-p/16139#M2234</guid>
      <dc:creator>GertNissen</dc:creator>
      <dc:date>2009-04-07T23:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: Parse text String into different Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-text-String-into-different-Variables/m-p/16140#M2235</link>
      <description>You could try this also:&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
&lt;BR /&gt;
S='AAAA AAAA AAAA AAA AAAAA AAAAAA, AAAAA AAAA AAAAAAAAAAAAA BBB BBBBB BBBBB BBBBB BBBBBB BBBBB BBBBBBB BBBBBBBBBBBB CCCCCCC CCCCC CCCCCCC CCCCCCC CCCCC CCCC CCCCCCCCCC DDDD DDDDD DDDD DDDDDDD DDDDD DDDDDDDD DDDD DDDDD DDDDDD DDDDD DDDD';&lt;BR /&gt;
&lt;BR /&gt;
I1=1*55+index(substr(S,55),' ')-1; /* 1st split starting at 55 */&lt;BR /&gt;
I2=2*55+index(substr(S,2*55),' ')-1; /* 2nd split starting at 2x55 */&lt;BR /&gt;
I3=3*55+index(substr(S,3*55),' ')-1; /* 3rd split starting at 3x55 */&lt;BR /&gt;
VAR1=substr(S,1,I1); &lt;BR /&gt;
VAR2=substr(S,I1,I2-I1);&lt;BR /&gt;
VAR3=substr(S,I2,I3-I2);&lt;BR /&gt;
VAR4=substr(S,I3);&lt;BR /&gt;
&lt;BR /&gt;
/* result */&lt;BR /&gt;
put VAR1=;&lt;BR /&gt;
put VAR2=;&lt;BR /&gt;
put VAR3=;&lt;BR /&gt;
put VAR4=;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Greetings from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos at &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
      <pubDate>Wed, 08 Apr 2009 11:21:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-text-String-into-different-Variables/m-p/16140#M2235</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-04-08T11:21:02Z</dc:date>
    </item>
  </channel>
</rss>

