<?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: cutting of data up to 200 characters in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/cutting-of-data-up-to-200-characters/m-p/754064#M237732</link>
    <description>&lt;P&gt;I recommend to not limit yourself by a fixed number of text pieces, use a vertical layout instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
length text $200;
set have;
do until (lengthn(str) = 0);
  text = substr(str,1,200);
  call scan(text,-1,pos,len," ");
  if pos + len lt 200 then pos = pos + len;
  str = substr(str,pos);
  text = substr(text,1,pos);
  output;
end;
keep text;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 14 Jul 2021 13:14:38 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-07-14T13:14:38Z</dc:date>
    <item>
      <title>cutting of data up to 200 characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cutting-of-data-up-to-200-characters/m-p/754057#M237731</link>
      <description>&lt;P&gt;If dataset has larger than 200 characters then 200 cutting off the setting at whole words with the first 200 characters going into text, the second set of 200 characters going into text1 and so fourth. Continue until all characters have been processed.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Query :&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;str = "Subject 1013 at v6 26AUG2020 was not reconsented with Main ICF (c ) v4.0 14AUG2020, IRB approval 19AUG2020, xxxxx Approval 20AUG2020. Subject 1013 was reconsented at V9 18NOV2020 with Main ICF (c ) v4.0 14AUG2020, IRB approval 19AUG2020, xxxxx Approval 20AUG2020.";output;&lt;BR /&gt;str= " a b c" ; output;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;So the output would be :&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;DIV id="tinyMceEditorpdhokriya_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pdhokriya_1-1626267621470.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/61242iB06911F619AF81AE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="pdhokriya_1-1626267621470.png" alt="pdhokriya_1-1626267621470.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="50%" height="30px"&gt;text&lt;/TD&gt;
&lt;TD width="25%"&gt;text1&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;text2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="167px"&gt;Subject 1013 at v6 26AUG2020 was not reconsented with Main ICF (c ) v4.0 14AUG2020, IRB approval 19AUG2020, xxxxx Approval 20AUG2020. Subject 1013 was reconsented at V9 18NOV2020 with Main ICF (c )&lt;/TD&gt;
&lt;TD width="25%"&gt;v4.0 14AUG2020, IRB approval 19AUG2020, Lilly Approval 20AUG2020.&lt;/TD&gt;
&lt;TD width="25%" height="167px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="30px"&gt;a b c&lt;/TD&gt;
&lt;TD width="25%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Wed, 14 Jul 2021 13:00:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cutting-of-data-up-to-200-characters/m-p/754057#M237731</guid>
      <dc:creator>pdhokriya</dc:creator>
      <dc:date>2021-07-14T13:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: cutting of data up to 200 characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cutting-of-data-up-to-200-characters/m-p/754064#M237732</link>
      <description>&lt;P&gt;I recommend to not limit yourself by a fixed number of text pieces, use a vertical layout instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
length text $200;
set have;
do until (lengthn(str) = 0);
  text = substr(str,1,200);
  call scan(text,-1,pos,len," ");
  if pos + len lt 200 then pos = pos + len;
  str = substr(str,pos);
  text = substr(text,1,pos);
  output;
end;
keep text;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Jul 2021 13:14:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cutting-of-data-up-to-200-characters/m-p/754064#M237732</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-07-14T13:14:38Z</dc:date>
    </item>
    <item>
      <title>Re: cutting of data up to 200 characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cutting-of-data-up-to-200-characters/m-p/754068#M237733</link>
      <description>&lt;P&gt;Observation 2 should be in another variable ( text1).&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jul 2021 13:54:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cutting-of-data-up-to-200-characters/m-p/754068#M237733</guid>
      <dc:creator>pdhokriya</dc:creator>
      <dc:date>2021-07-14T13:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: cutting of data up to 200 characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cutting-of-data-up-to-200-characters/m-p/754075#M237737</link>
      <description>&lt;P&gt;You need to predefine the variables ahead of time so you that means before you start your step you need to know the maximum number of variables you'll need for each string. Instead of that, a more dynamic method is to do it in a long format, so each observation to each line and then transpose it afterwards to a wide format if necessary. It's usually more efficient to work in the long format generally but it takes some training and experience to get there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/55374"&gt;@pdhokriya&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Observation 2 should be in another variable ( text1).&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Transposing data tutorials:&lt;BR /&gt;Long to Wide:&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Wide to Long:&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;And sometimes a double transpose is needed for extra wide data sets:&lt;BR /&gt;&lt;A href="https://gist.github.com/statgeek/2321b6f62ab78d5bf2b0a5a8626bd7cd" target="_blank"&gt;https://gist.github.com/statgeek/2321b6f62ab78d5bf2b0a5a8626bd7cd&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jul 2021 14:12:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cutting-of-data-up-to-200-characters/m-p/754075#M237737</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-07-14T14:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: cutting of data up to 200 characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cutting-of-data-up-to-200-characters/m-p/754081#M237741</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/55374"&gt;@pdhokriya&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Observation 2 should be in another variable ( text1).&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I&amp;nbsp;&lt;STRONG&gt;VERY STRONGLY&lt;/STRONG&gt; advise against such coding techniques. They only make your further data handling complicated and serve no purpose in about 99.95 % of cases, especially as observed here on the communities. Cleanse your brain of the poisons of Excel thinking.&lt;/P&gt;
&lt;P&gt;Please give me a valid reason why you want a limited set of text variables that you might run out of if str becomes longer than expected.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jul 2021 14:23:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cutting-of-data-up-to-200-characters/m-p/754081#M237741</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-07-14T14:23:22Z</dc:date>
    </item>
    <item>
      <title>Re: cutting of data up to 200 characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cutting-of-data-up-to-200-characters/m-p/754083#M237742</link>
      <description>&lt;P&gt;Can you describe what you will do with the resulting data, and why 200 characters as a magic number is desired?&lt;/P&gt;
&lt;P&gt;If you have an arbitrary 200 character split then you are extremely likely to have words split in the middle with bits in two separate variables. Which means that finding values or actual use of the reduced variables seems hardly worth it.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jul 2021 14:26:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cutting-of-data-up-to-200-characters/m-p/754083#M237742</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-14T14:26:30Z</dc:date>
    </item>
    <item>
      <title>Re: cutting of data up to 200 characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cutting-of-data-up-to-200-characters/m-p/754094#M237747</link>
      <description>&lt;P&gt;It is not hard to adapt&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;solution to generating multiple variables instead.&lt;/P&gt;
&lt;P&gt;Calculate the number of variables you will need by dividing the max length of your source variable by 200 and adding at least one more to handle the inefficiency caused by not splitting words in the middle.&amp;nbsp; So for example if STR is length 800 you might use 5 as the number of new TEXT variables to create.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  array text [5] $200;
  do nwords=1 to dim(text) until (lengthn(str) = 0);
    text[nwords] = str;
    call scan(text[nwords],-1,pos,len," ");
    if pos + len lt 200 then pos = pos + len;
    str = substr(str,pos);
    text[nwords] = substr(text[nwords],1,pos);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you end up with some observations where STR is not empty then re-run with a larger array.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jul 2021 15:00:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cutting-of-data-up-to-200-characters/m-p/754094#M237747</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-14T15:00:44Z</dc:date>
    </item>
  </channel>
</rss>

