<?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: splitting text which is more than 200char to multiple variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/splitting-text-which-is-more-than-200char-to-multiple-variables/m-p/333670#M75234</link>
    <description>&lt;P&gt;Search it firstly at this community. There are already a couple of questions have been answered.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options noquotelenmax;
data have;
id=1;
 var = '
But multiple notes over the past three weeks have undermined the shock last November, wiping out 86% of the money in circulation in a cash-driven economy.
The demonetisation exercise has been called a watershed for a country saddled with counterfeiters pushing millions of fake notes into the Indian economy from neighbouring Pakistan, Bangladesh and Nepal. Terrorists and governments hostile to India use the bogus cash to weaken the economy.
The latest attempts to restart the vicious cycle after the notes ban have set off alarm bells in the security establishment.
';
run;
data temp;
 set have;
 do i=1 to countw(var,' ');
  word=scan(var,i,' ');output;
 end;
 drop i var;
run;
data temp;
 set temp;
 by id;
 if first.id then sum=0;
 sum+(length(word)+1);
 if sum gt 200 then do;group+1;sum=length(word);end;
 drop sum ; 
run;
data x;
 length x $ 200;
 do until(last.group);
  set temp;
  by id group;
  x=catx(' ',x,word);
 end;
run;
proc transpose data=x out=want;
by id ;
var x;
run;
proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 17 Feb 2017 04:21:31 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2017-02-17T04:21:31Z</dc:date>
    <item>
      <title>splitting text which is more than 200char to multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/splitting-text-which-is-more-than-200char-to-multiple-variables/m-p/333393#M75114</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Dear member&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please let me know How to split a content more than 200 chr. using no macros, i mean with a datasetp.&lt;/P&gt;&lt;P&gt;For eg. if a content given is more than 500chars. in a datastep should split according to it's size(200chars.) and without truncating &amp;nbsp;words.&lt;/P&gt;&lt;P&gt;eg. var = '&lt;/P&gt;&lt;P&gt;But multiple&amp;nbsp;notes over the past three weeks have undermined the shock&amp;nbsp;last November, wiping out 86% of the money in circulation in a cash-driven economy.&lt;/P&gt;&lt;P&gt;The demonetisation exercise has been called a watershed for a country saddled with counterfeiters pushing millions of fake notes into the Indian economy from neighbouring Pakistan, Bangladesh and Nepal. Terrorists and governments hostile to India use the bogus cash to weaken the economy.&lt;/P&gt;&lt;P&gt;The latest attempts to restart the vicious cycle after the notes ban have set off alarm bells in the security establishment.&lt;/P&gt;&lt;P&gt;'&lt;/P&gt;&lt;P&gt;to var, var1 and var2, excess content should split from var to var1 and var2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;-santosh&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2017 14:37:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/splitting-text-which-is-more-than-200char-to-multiple-variables/m-p/333393#M75114</guid>
      <dc:creator>ysantosh18</dc:creator>
      <dc:date>2017-02-16T14:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: splitting text which is more than 200char to multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/splitting-text-which-is-more-than-200char-to-multiple-variables/m-p/333399#M75117</link>
      <description>&lt;P&gt;Here are some DATA step statements to accomplish this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;length var1 $ 500&amp;nbsp; var2 $ 200;&lt;/P&gt;
&lt;P&gt;if length(var) &amp;gt;= 200 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; do i=201 to 1 by -1 until (var1 &amp;gt; ' ');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if substr(var, i, 1)=' ' then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var1 = left(substr(var, i+1));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var = substr(var, 1, i);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;if length(var1) &amp;gt;= 200 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; do i=201 to 1 by -1 until (var2 &amp;gt; ' ');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if substr(var1, i, 1)=' ' then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var2 = left(substr(var1, i+1));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var1 = substr(var1, 1, i);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's untested, but should be fine as is.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2017 14:46:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/splitting-text-which-is-more-than-200char-to-multiple-variables/m-p/333399#M75117</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-02-16T14:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: splitting text which is more than 200char to multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/splitting-text-which-is-more-than-200char-to-multiple-variables/m-p/333426#M75126</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following may work for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let NUM_OF_STR=5;&lt;BR /&gt;%let CHR_PER_STR=40;&lt;BR /&gt;data _null_;&lt;BR /&gt;array V {*} $ &amp;amp;CHR_PER_STR V1-V&amp;amp;NUM_OF_STR;&lt;BR /&gt;S='the demonetisation exercise has been called a watershed for a country saddled with counterfeiters pushing';&lt;BR /&gt;_I=1; _J=1;&lt;BR /&gt;do until (scan(S,_I,' ') eq '');&lt;BR /&gt;   _W=scan(S,_I,' ');&lt;BR /&gt;   if lengthn(V[_J])+lengthn(_W) &amp;gt; lengthc(V[_J]) then _J+1;&lt;BR /&gt;   V[_J]=strip(V[_J])!!' '!!_W;&lt;BR /&gt;   _I+1;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nothing fancy, it will split the text word by word and ditribute it by the number of desired variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will also remove consecutive blanks&amp;nbsp;between words if any.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Daniel Santos&amp;nbsp;@ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2017 15:34:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/splitting-text-which-is-more-than-200char-to-multiple-variables/m-p/333426#M75126</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2017-02-16T15:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: splitting text which is more than 200char to multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/splitting-text-which-is-more-than-200char-to-multiple-variables/m-p/333429#M75128</link>
      <description>thank you, let me check, will get back to you&lt;BR /&gt;&lt;BR /&gt;thanks again&lt;BR /&gt;santosh&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
      <pubDate>Thu, 16 Feb 2017 15:37:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/splitting-text-which-is-more-than-200char-to-multiple-variables/m-p/333429#M75128</guid>
      <dc:creator>ysantosh18</dc:creator>
      <dc:date>2017-02-16T15:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: splitting text which is more than 200char to multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/splitting-text-which-is-more-than-200char-to-multiple-variables/m-p/333434#M75130</link>
      <description>&lt;P&gt;The two suggestions offered may work (I don't have time to test them) and, if so, you can disregard this one. SAS notes has published a macro that splits lines of text (see:&amp;nbsp;&lt;A href="http://support.sas.com/kb/30/649.html" target="_blank"&gt;http://support.sas.com/kb/30/649.html&lt;/A&gt; ). The following is a slight bastardization of that macro that meets your current need. You should note that your example text line is longer than 500 characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
  informat var $char600.;
  infile 'c:\art\testdata.txt' lrecl=600;
  input var &amp;amp;;
;

data want (keep=var:);
  array var(3) $200.;
  length textin $600;
  set have (rename=var=_var);
  textin=_var;
  i=1;
  if lengthn( textin ) &amp;lt;= 200 then var(i)=textin;
  else do while( lengthn( textin ) &amp;gt; 200 ) ;
    var(i) = reverse( substr( textin, 1, 200 )) ;
    ndx = index( var(i), ' ' ) ;
    if ndx then do ;
      var(i) = reverse( substr( var(i), ndx + 1 )) ;
      i+1;
      textin = substr( textin, 200 - ndx + 1 ) ;
    end ;
    else do;
      var(i) = substr(textin,1,200);
      i+1;
      textin = substr(textin,200+1);
    end;
    if lengthn( textin ) le 200 then var(i)=textin;
  end ;
run;
&lt;/PRE&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2017 15:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/splitting-text-which-is-more-than-200char-to-multiple-variables/m-p/333434#M75130</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-16T15:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: splitting text which is more than 200char to multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/splitting-text-which-is-more-than-200char-to-multiple-variables/m-p/333670#M75234</link>
      <description>&lt;P&gt;Search it firstly at this community. There are already a couple of questions have been answered.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options noquotelenmax;
data have;
id=1;
 var = '
But multiple notes over the past three weeks have undermined the shock last November, wiping out 86% of the money in circulation in a cash-driven economy.
The demonetisation exercise has been called a watershed for a country saddled with counterfeiters pushing millions of fake notes into the Indian economy from neighbouring Pakistan, Bangladesh and Nepal. Terrorists and governments hostile to India use the bogus cash to weaken the economy.
The latest attempts to restart the vicious cycle after the notes ban have set off alarm bells in the security establishment.
';
run;
data temp;
 set have;
 do i=1 to countw(var,' ');
  word=scan(var,i,' ');output;
 end;
 drop i var;
run;
data temp;
 set temp;
 by id;
 if first.id then sum=0;
 sum+(length(word)+1);
 if sum gt 200 then do;group+1;sum=length(word);end;
 drop sum ; 
run;
data x;
 length x $ 200;
 do until(last.group);
  set temp;
  by id group;
  x=catx(' ',x,word);
 end;
run;
proc transpose data=x out=want;
by id ;
var x;
run;
proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Feb 2017 04:21:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/splitting-text-which-is-more-than-200char-to-multiple-variables/m-p/333670#M75234</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-02-17T04:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: splitting text which is more than 200char to multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/splitting-text-which-is-more-than-200char-to-multiple-variables/m-p/333739#M75255</link>
      <description>thank you, looks like you are genius in SAS, but am a beginner, and here i&lt;BR /&gt;don't know the number of strings to split, It should depend on only length&lt;BR /&gt;&lt;BR /&gt;thanks&lt;BR /&gt;Santosh</description>
      <pubDate>Fri, 17 Feb 2017 11:03:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/splitting-text-which-is-more-than-200char-to-multiple-variables/m-p/333739#M75255</guid>
      <dc:creator>ysantosh18</dc:creator>
      <dc:date>2017-02-17T11:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: splitting text which is more than 200char to multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/splitting-text-which-is-more-than-200char-to-multiple-variables/m-p/333744#M75260</link>
      <description>&lt;P&gt;Oh, I'm surely not a genius, but thanks for the compliment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And no problem with that. If you want to set only CHR_PER_STR and have NUM_OF_STR calculated dynamically, instead of:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let NUM_OF_STR=5;&lt;BR /&gt;%let CHR_PER_STR=40;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let CHR_PER_STR=200;
data _null_;
     set HAVE;
     call symputn('NUM_OF_STR',(lengthc(S)+&amp;amp;CHR_PER_STR-1)/&amp;amp;CHR_PER_STR);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will set NUM_OF_STR according to S's size and the specified CHR_PER_STR.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Daniel Santos&amp;nbsp;@ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 11:49:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/splitting-text-which-is-more-than-200char-to-multiple-variables/m-p/333744#M75260</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2017-02-17T11:49:38Z</dc:date>
    </item>
  </channel>
</rss>

