<?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: To split values for Above 200 length in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/To-split-values-for-Above-200-length/m-p/930096#M365940</link>
    <description>&lt;P&gt;Something like below should work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  row_id=_n_;
  length row_id 8 term $2000;
  row_id=1;
  term='The length of this text is a very long text. As per CDISC standards, all variables in datasets should have a maximum length of 200 characters. As a consequence, this text needs to be split into variables TERM1, TERM2, ... TERMX, with each having 200 characters long.';
  output;
  row_id=2;
  term=repeat('aaa bbb ',180);
  output;
run;

data split_200(keep=row_id term_:);
  length term_200 $200;
  set have;
  _pos_start=1;
  _pos_stop =_pos_start+200;

  do term_no=1 by 1;
    _pos_found=findc(term,' ',-_pos_stop);
    term_200  =substr(term,_pos_start,_pos_found-_pos_start);
    if missing(term_200) then leave;
    output;
    _pos_start=_pos_found+1;
    _pos_stop =_pos_start+200;
  end;
run;

proc transpose data=split_200 out=split_200_transp(drop=_name_) prefix=term_;
  by row_id;
  id term_no;
  var term_200;
run;

data want;
  merge have split_200_transp;
  by row_id;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1716973868557.png" style="width: 841px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96828iFFB09AF05CD19FED/image-dimensions/841x213?v=v2" width="841" height="213" role="button" title="Patrick_0-1716973868557.png" alt="Patrick_0-1716973868557.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 29 May 2024 09:44:07 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2024-05-29T09:44:07Z</dc:date>
    <item>
      <title>To split values for Above 200 length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-split-values-for-Above-200-length/m-p/930052#M365933</link>
      <description>&lt;BR /&gt;The length of this text is a very long text. As per CDISC standards, all variables in datasets should have a maximum length of 200 characters. As a consequence, this text needs to be split into variables TERM1, TERM2, ... TERMX, with each having 200 characters long.</description>
      <pubDate>Wed, 29 May 2024 05:30:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-split-values-for-Above-200-length/m-p/930052#M365933</guid>
      <dc:creator>Maneesh27</dc:creator>
      <dc:date>2024-05-29T05:30:34Z</dc:date>
    </item>
    <item>
      <title>Re: To split values for Above 200 length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-split-values-for-Above-200-length/m-p/930096#M365940</link>
      <description>&lt;P&gt;Something like below should work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  row_id=_n_;
  length row_id 8 term $2000;
  row_id=1;
  term='The length of this text is a very long text. As per CDISC standards, all variables in datasets should have a maximum length of 200 characters. As a consequence, this text needs to be split into variables TERM1, TERM2, ... TERMX, with each having 200 characters long.';
  output;
  row_id=2;
  term=repeat('aaa bbb ',180);
  output;
run;

data split_200(keep=row_id term_:);
  length term_200 $200;
  set have;
  _pos_start=1;
  _pos_stop =_pos_start+200;

  do term_no=1 by 1;
    _pos_found=findc(term,' ',-_pos_stop);
    term_200  =substr(term,_pos_start,_pos_found-_pos_start);
    if missing(term_200) then leave;
    output;
    _pos_start=_pos_found+1;
    _pos_stop =_pos_start+200;
  end;
run;

proc transpose data=split_200 out=split_200_transp(drop=_name_) prefix=term_;
  by row_id;
  id term_no;
  var term_200;
run;

data want;
  merge have split_200_transp;
  by row_id;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1716973868557.png" style="width: 841px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96828iFFB09AF05CD19FED/image-dimensions/841x213?v=v2" width="841" height="213" role="button" title="Patrick_0-1716973868557.png" alt="Patrick_0-1716973868557.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2024 09:44:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-split-values-for-Above-200-length/m-p/930096#M365940</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-05-29T09:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: To split values for Above 200 length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-split-values-for-Above-200-length/m-p/930100#M365941</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439436"&gt;@Maneesh27&lt;/a&gt;&amp;nbsp;Code in previous post just amended with a corrected expression for the substr() function.&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2024 09:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-split-values-for-Above-200-length/m-p/930100#M365941</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-05-29T09:45:04Z</dc:date>
    </item>
  </channel>
</rss>

