<?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 the text based on brackets using do loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-text-based-on-brackets-using-do-loop/m-p/555954#M154794</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
length text $1000;
text="The subject experienced [AESER] adverse event of [AESEV] intensity, reported as '[VBA]' ([LLT]).";
output;
text="[Samsung - the first major smartphone maker to release a foldable smartphone]";
output ;
text="School districts across the [COUNTRY] are on the cusp of integrating [new technology in K-12 classrooms] by such as [SOCIAL_MEDIA] use as early as preschool.exploring unexpected [CURRICULUM] such as Facebook/Twitter use as early as preschool.";
output;
run ;

data want;
	set have;
	length output_text $1000 char $1;
	array vars{100} $1000 var1-var100;
	output_text="";
	j=0; *number of output var;
	k=0; *char for output string;
	do i = 1 to 1000; *loop across original text;
		k + 1;
		char=substr(text,i,1);
		
		substr(output_text,k,1)=strip(char);
		if char = "[" and output_text ne "[" then do;
			j+1;
			vars{j}=substr(output_text,1,length(output_text)-1);
			output_text=strip("[");
			k=1;
		end;
		if char = "]" then do;
			j+1;
			k=0;
			vars{j}=strip(output_text);
			output_text="";
		end;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Ballardw's code is probably more intuitive.&lt;/P&gt;</description>
    <pubDate>Fri, 03 May 2019 14:56:31 GMT</pubDate>
    <dc:creator>noling</dc:creator>
    <dc:date>2019-05-03T14:56:31Z</dc:date>
    <item>
      <title>Splitting the text based on brackets using do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-text-based-on-brackets-using-do-loop/m-p/555930#M154784</link>
      <description>&lt;P&gt;Hi All&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have ;&lt;BR /&gt;text="The subject experienced [AESER] adverse event of [AESEV] intensity, reported as '[VBA]' ([LLT]).";&lt;BR /&gt;output;&lt;BR /&gt;text="[Samsung - the first major smartphone maker to release a foldable smartphone]";&lt;BR /&gt;output ;&lt;BR /&gt;text="School districts across the [COUNTRY] are on the cusp of integrating [new technology in K-12 classrooms] by such as [SOCIAL_MEDIA] use as early as preschool.exploring unexpected [CURRICULUM] such as Facebook/Twitter use as early as preschool.";&lt;BR /&gt;output;&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i want to split the entire text into multiple variables based on the square/Angular brackets ([), both start and close brackets along with the text present in the brackets&amp;nbsp; should be present in each variable as shown below. Tried with do loop and array, something missing in the loop . Can any one suggest how to perform this split.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="0" frame="VOID" rules="NONE" cellspacing="0"&gt;&lt;COLGROUP&gt;&lt;COL width="152" /&gt;&lt;COL width="86" /&gt;&lt;COL width="86" /&gt;&lt;COL width="86" /&gt;&lt;COL width="86" /&gt;&lt;COL width="86" /&gt;&lt;COL width="86" /&gt;&lt;COL width="86" /&gt;&lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD height="20" align="LEFT" style="width: 96px;"&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;VAR1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 82px;"&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;VAR2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 72px;"&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;VAR3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 80px;"&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;VAR4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 63px;"&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;VAR5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 116px;"&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;VAR6&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 126px;"&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;VAR7&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 111px;"&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;VAR8&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="38" align="LEFT" style="width: 96px;"&gt;&lt;FONT color="#000000"&gt;The subject experienced &lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 82px;"&gt;&lt;FONT color="#000000"&gt;[AESER] &lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 72px;"&gt;&lt;FONT color="#000000"&gt;adverse event of &lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 80px;"&gt;&lt;FONT color="#000000"&gt;[AESEV] &lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 63px;"&gt;&lt;FONT color="#000000"&gt;intensity, reported as &lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 116px;"&gt;&lt;FONT color="#000000"&gt;[VBA]' &lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 126px;"&gt;&lt;FONT color="#000000"&gt;([LLT])&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 111px;"&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="74" align="LEFT" style="width: 96px;"&gt;&lt;FONT color="#000000"&gt;[Samsung - the first major smartphone maker to release a foldable smartphone]&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 82px;"&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 72px;"&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 80px;"&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 63px;"&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 116px;"&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 126px;"&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 111px;"&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="92" align="LEFT" style="width: 96px;"&gt;&lt;FONT color="#000000"&gt;School districts across the&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 82px;"&gt;&lt;FONT color="#000000"&gt;[COUNTRY] &lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 72px;"&gt;&lt;FONT color="#000000"&gt;are on the cusp of integrating&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 80px;"&gt;&lt;FONT color="#000000"&gt;[new technology in K-12 classrooms]&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 63px;"&gt;&lt;FONT color="#000000"&gt;by such as&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 116px;"&gt;&lt;FONT color="#000000"&gt;[SOCIAL_MEDIA]&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 126px;"&gt;&lt;FONT color="#000000"&gt;use as early as preschool.exploring unexpected&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 111px;"&gt;&lt;FONT color="#000000"&gt;such as Facebook/Twitter use as early as preschool.&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 13:51:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-text-based-on-brackets-using-do-loop/m-p/555930#M154784</guid>
      <dc:creator>keen_sas</dc:creator>
      <dc:date>2019-05-03T13:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting the text based on brackets using do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-text-based-on-brackets-using-do-loop/m-p/555950#M154790</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16518"&gt;@keen_sas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi All&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have ;&lt;BR /&gt;text="The subject experienced [AESER] adverse event of [AESEV] intensity, reported as '[VBA]' ([LLT]).";&lt;BR /&gt;output;&lt;BR /&gt;text="[Samsung - the first major smartphone maker to release a foldable smartphone]";&lt;BR /&gt;output ;&lt;BR /&gt;text="School districts across the [COUNTRY] are on the cusp of integrating [new technology in K-12 classrooms] by such as [SOCIAL_MEDIA] use as early as preschool.exploring unexpected [CURRICULUM] such as Facebook/Twitter use as early as preschool.";&lt;BR /&gt;output;&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i want to split the entire text into multiple variables based on the square/Angular brackets ([), both start and close brackets along with the text present in the brackets&amp;nbsp; should be present in each variable as shown below. Tried with do loop and array, something missing in the loop . Can any one suggest how to perform this split.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="0" rules="NONE" frame="VOID" cellspacing="0"&gt;&lt;COLGROUP&gt;&lt;COL width="152" /&gt;&lt;COL width="86" /&gt;&lt;COL width="86" /&gt;&lt;COL width="86" /&gt;&lt;COL width="86" /&gt;&lt;COL width="86" /&gt;&lt;COL width="86" /&gt;&lt;COL width="86" /&gt;&lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD height="20" align="LEFT" style="width: 96px;"&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;VAR1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 82px;"&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;VAR2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 72px;"&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;VAR3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 80px;"&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;VAR4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 63px;"&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;VAR5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 116px;"&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;VAR6&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 126px;"&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;VAR7&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 111px;"&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;VAR8&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="38" align="LEFT" style="width: 96px;"&gt;&lt;FONT color="#000000"&gt;The subject experienced &lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 82px;"&gt;&lt;FONT color="#000000"&gt;[AESER] &lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 72px;"&gt;&lt;FONT color="#000000"&gt;adverse event of &lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 80px;"&gt;&lt;FONT color="#000000"&gt;[AESEV] &lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 63px;"&gt;&lt;FONT color="#000000"&gt;intensity, reported as &lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 116px;"&gt;&lt;FONT color="#000000"&gt;[VBA]' &lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 126px;"&gt;&lt;FONT color="#000000"&gt;([LLT])&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 111px;"&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="74" align="LEFT" style="width: 96px;"&gt;&lt;FONT color="#000000"&gt;[Samsung - the first major smartphone maker to release a foldable smartphone]&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 82px;"&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 72px;"&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 80px;"&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 63px;"&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 116px;"&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 126px;"&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 111px;"&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="92" align="LEFT" style="width: 96px;"&gt;&lt;FONT color="#000000"&gt;School districts across the&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 82px;"&gt;&lt;FONT color="#000000"&gt;[COUNTRY] &lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 72px;"&gt;&lt;FONT color="#000000"&gt;are on the cusp of integrating&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 80px;"&gt;&lt;FONT color="#000000"&gt;[new technology in K-12 classrooms]&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 63px;"&gt;&lt;FONT color="#000000"&gt;by such as&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 116px;"&gt;&lt;FONT color="#000000"&gt;[SOCIAL_MEDIA]&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 126px;"&gt;&lt;FONT color="#000000"&gt;use as early as preschool.exploring unexpected&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="LEFT" style="width: 111px;"&gt;&lt;FONT color="#000000"&gt;such as Facebook/Twitter use as early as preschool.&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You have some requirements that are moderately odd, such as why does [VBA]'&amp;nbsp; have the ' as part of the value, and why does ([LLT]) have both parentheses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps if you describe how the result will actual be used we can make some additional suggestions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This may help you get started but your rules for when to include the [] as part of the value need a lot of explanation.&lt;/P&gt;
&lt;P&gt;Note, your example data set cuts off the third example row because you did not define a maximum length for TEXT and the first line sets the length of the text variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have ;
length text $ 1000;
text="The subject experienced [AESER] adverse event of [AESEV] intensity, reported as '[VBA]' ([LLT]).";
output;
text="[Samsung - the first major smartphone maker to release a foldable smartphone]";
output ;
text="School districts across the [COUNTRY] are on the cusp of integrating [new technology in K-12 classrooms] by such as [SOCIAL_MEDIA] use as early as preschool.exploring unexpected [CURRICULUM] such as Facebook/Twitter use as early as preschool.";
output;
run;

data need (keep= row phrase);
  set have;
  row = _n_;
  length phrase $ 100;

  do i= 1 to countw(text,'[]');
   phrase = scan(text,i,'[]');
   output;
  end;
run;

proc transpose data=need
     out=trans prefix=var
     ;
by row;
var phrase;
run;
&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 May 2019 14:45:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-text-based-on-brackets-using-do-loop/m-p/555950#M154790</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-03T14:45:52Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting the text based on brackets using do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-text-based-on-brackets-using-do-loop/m-p/555954#M154794</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
length text $1000;
text="The subject experienced [AESER] adverse event of [AESEV] intensity, reported as '[VBA]' ([LLT]).";
output;
text="[Samsung - the first major smartphone maker to release a foldable smartphone]";
output ;
text="School districts across the [COUNTRY] are on the cusp of integrating [new technology in K-12 classrooms] by such as [SOCIAL_MEDIA] use as early as preschool.exploring unexpected [CURRICULUM] such as Facebook/Twitter use as early as preschool.";
output;
run ;

data want;
	set have;
	length output_text $1000 char $1;
	array vars{100} $1000 var1-var100;
	output_text="";
	j=0; *number of output var;
	k=0; *char for output string;
	do i = 1 to 1000; *loop across original text;
		k + 1;
		char=substr(text,i,1);
		
		substr(output_text,k,1)=strip(char);
		if char = "[" and output_text ne "[" then do;
			j+1;
			vars{j}=substr(output_text,1,length(output_text)-1);
			output_text=strip("[");
			k=1;
		end;
		if char = "]" then do;
			j+1;
			k=0;
			vars{j}=strip(output_text);
			output_text="";
		end;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Ballardw's code is probably more intuitive.&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 14:56:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-text-based-on-brackets-using-do-loop/m-p/555954#M154794</guid>
      <dc:creator>noling</dc:creator>
      <dc:date>2019-05-03T14:56:31Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting the text based on brackets using do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-text-based-on-brackets-using-do-loop/m-p/556000#M154813</link>
      <description>&lt;P&gt;Some of the values seem to be inconsistent:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;In the first line: why is the ' after [VBA] included in var6, but not the ' before the opening square bracket?&lt;/LI&gt;
&lt;LI&gt;in the third line: why is [CURRICULUM]&amp;nbsp; not in a variable?&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is another suggestion to solve the issue:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.intermediate;
    set have;
    
    length
        id 8
        part $ 400
        _start _stop _pos _len 8
    ;
    
    drop _: text;
    
    id = _n_;
    rx = prxparse('/(.*?)(\(?\[.+?\]\)?)/');
    _start = 1;
    _stop = length(text);
    
    put _stop=;
    
    call prxnext(rx, _start, _stop, text, _pos, _len);
    
    do while (_pos &amp;gt; 0);
        do i = 1 to 3;
            part = prxposn(rx, i, text);
            if not missing(part) then output;
        end;   
        call prxnext(rx, _start, _stop, text, _pos, _len);
    end;
    
    put _start= _stop= _len= _pos=;
    
    if _start &amp;lt; _stop then do;
        part = substr(text, _start);
        output;
    end;
    
run;


proc transpose data=work.intermediate out=work.want(drop=id _name_) prefix=var;
    by id;
    var part;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 May 2019 16:26:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-text-based-on-brackets-using-do-loop/m-p/556000#M154813</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-05-03T16:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting the text based on brackets using do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-text-based-on-brackets-using-do-loop/m-p/556348#M154989</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/115150"&gt;@noling&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;for your quick response. The inconsistencies in the output which i have displayed is my typo mistake.But the concept is to split the text based on [] ( square brackets) and all of the 3 solutions are working fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;solution is intuitive , but i have one query here.Since the code is using Scan function&amp;nbsp; &lt;STRONG&gt;phrase = scan(text,i,'[]');&lt;/STRONG&gt;&amp;nbsp; the output is excluding the square brackets , the phrase (text) should be inclusive of square brackets as shown below.&lt;/P&gt;
&lt;TABLE style="height: 229px;" width="657"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 19px;"&gt;
&lt;TD style="height: 19px; width: 61px;"&gt;Row&lt;/TD&gt;
&lt;TD style="height: 19px; width: 283px;"&gt;Phrase&lt;/TD&gt;
&lt;TD style="height: 19px; width: 267px;"&gt;Required Output&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 19px;"&gt;
&lt;TD style="height: 19px; width: 61px;"&gt;1&lt;/TD&gt;
&lt;TD style="height: 19px; width: 283px;"&gt;The subject experienced&lt;/TD&gt;
&lt;TD style="height: 19px; width: 267px;"&gt;The subject experienced&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 19px;"&gt;
&lt;TD style="height: 19px; width: 61px;"&gt;1&lt;/TD&gt;
&lt;TD style="height: 19px; width: 283px;"&gt;AESER&lt;/TD&gt;
&lt;TD style="height: 19px; width: 267px;"&gt;&lt;STRONG&gt;[AESER]&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 19px;"&gt;
&lt;TD style="height: 19px; width: 61px;"&gt;1&lt;/TD&gt;
&lt;TD style="height: 19px; width: 283px;"&gt;&amp;nbsp;adverse event of&lt;/TD&gt;
&lt;TD style="height: 19px; width: 267px;"&gt;&amp;nbsp;adverse event of&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 19px;"&gt;
&lt;TD style="height: 19px; width: 61px;"&gt;1&lt;/TD&gt;
&lt;TD style="height: 19px; width: 283px;"&gt;AESEV&lt;/TD&gt;
&lt;TD style="height: 19px; width: 267px;"&gt;&lt;STRONG&gt;[AESEV]&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 19px;"&gt;
&lt;TD style="height: 19px; width: 61px;"&gt;1&lt;/TD&gt;
&lt;TD style="height: 19px; width: 283px;"&gt;&amp;nbsp;intensity, reported as '&lt;/TD&gt;
&lt;TD style="height: 19px; width: 267px;"&gt;&amp;nbsp;intensity, reported as '&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 19px;"&gt;
&lt;TD style="height: 19px; width: 61px;"&gt;1&lt;/TD&gt;
&lt;TD style="height: 19px; width: 283px;"&gt;VBA&lt;/TD&gt;
&lt;TD style="height: 19px; width: 267px;"&gt;&lt;STRONG&gt;[VBA]&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 19px;"&gt;
&lt;TD style="height: 19px; width: 61px;"&gt;1&lt;/TD&gt;
&lt;TD style="height: 19px; width: 283px;"&gt;' (&lt;/TD&gt;
&lt;TD style="height: 19px; width: 267px;"&gt;' (&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 19px;"&gt;
&lt;TD style="height: 19px; width: 61px;"&gt;1&lt;/TD&gt;
&lt;TD style="height: 19px; width: 283px;"&gt;LLT&lt;/TD&gt;
&lt;TD style="height: 19px; width: 267px;"&gt;&lt;STRONG&gt;[LLT]&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 19px;"&gt;
&lt;TD style="height: 19px; width: 61px;"&gt;1&lt;/TD&gt;
&lt;TD style="height: 19px; width: 283px;"&gt;).&lt;/TD&gt;
&lt;TD style="height: 19px; width: 267px;"&gt;).&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 39px;"&gt;
&lt;TD style="height: 39px; width: 61px;"&gt;2&lt;/TD&gt;
&lt;TD style="height: 39px; width: 283px;"&gt;Samsung - the first major smartphone maker to release a foldable smartphone&lt;/TD&gt;
&lt;TD style="height: 39px; width: 267px;"&gt;&lt;STRONG&gt;[Samsung - the first major smartphone maker to release a foldable smartphone]&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The solutions provide good start to go ahead.&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 04:32:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-text-based-on-brackets-using-do-loop/m-p/556348#M154989</guid>
      <dc:creator>keen_sas</dc:creator>
      <dc:date>2019-05-06T04:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting the text based on brackets using do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-text-based-on-brackets-using-do-loop/m-p/556454#M155013</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16518"&gt;@keen_sas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/115150"&gt;@noling&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;for your quick response. The inconsistencies in the output which i have displayed is my typo mistake.But the concept is to split the text based on [] ( square brackets) and all of the 3 solutions are working fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;solution is intuitive , but i have one query here.Since the code is using Scan function&amp;nbsp; &lt;STRONG&gt;phrase = scan(text,i,'[]');&lt;/STRONG&gt;&amp;nbsp; the output is excluding the square brackets , the phrase (text) should be inclusive of square brackets as shown below.&lt;/P&gt;
&lt;TABLE width="657" style="height: 229px;"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 19px;"&gt;
&lt;TD style="width: 61px; height: 19px;"&gt;Row&lt;/TD&gt;
&lt;TD style="width: 283px; height: 19px;"&gt;Phrase&lt;/TD&gt;
&lt;TD style="width: 267px; height: 19px;"&gt;Required Output&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 19px;"&gt;
&lt;TD style="width: 61px; height: 19px;"&gt;1&lt;/TD&gt;
&lt;TD style="width: 283px; height: 19px;"&gt;The subject experienced&lt;/TD&gt;
&lt;TD style="width: 267px; height: 19px;"&gt;The subject experienced&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 19px;"&gt;
&lt;TD style="width: 61px; height: 19px;"&gt;1&lt;/TD&gt;
&lt;TD style="width: 283px; height: 19px;"&gt;AESER&lt;/TD&gt;
&lt;TD style="width: 267px; height: 19px;"&gt;&lt;STRONG&gt;[AESER]&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 19px;"&gt;
&lt;TD style="width: 61px; height: 19px;"&gt;1&lt;/TD&gt;
&lt;TD style="width: 283px; height: 19px;"&gt;&amp;nbsp;adverse event of&lt;/TD&gt;
&lt;TD style="width: 267px; height: 19px;"&gt;&amp;nbsp;adverse event of&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 19px;"&gt;
&lt;TD style="width: 61px; height: 19px;"&gt;1&lt;/TD&gt;
&lt;TD style="width: 283px; height: 19px;"&gt;AESEV&lt;/TD&gt;
&lt;TD style="width: 267px; height: 19px;"&gt;&lt;STRONG&gt;[AESEV]&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 19px;"&gt;
&lt;TD style="width: 61px; height: 19px;"&gt;1&lt;/TD&gt;
&lt;TD style="width: 283px; height: 19px;"&gt;&amp;nbsp;intensity, reported as '&lt;/TD&gt;
&lt;TD style="width: 267px; height: 19px;"&gt;&amp;nbsp;intensity, reported as '&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 19px;"&gt;
&lt;TD style="width: 61px; height: 19px;"&gt;1&lt;/TD&gt;
&lt;TD style="width: 283px; height: 19px;"&gt;VBA&lt;/TD&gt;
&lt;TD style="width: 267px; height: 19px;"&gt;&lt;STRONG&gt;[VBA]&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 19px;"&gt;
&lt;TD style="width: 61px; height: 19px;"&gt;1&lt;/TD&gt;
&lt;TD style="width: 283px; height: 19px;"&gt;' (&lt;/TD&gt;
&lt;TD style="width: 267px; height: 19px;"&gt;' (&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 19px;"&gt;
&lt;TD style="width: 61px; height: 19px;"&gt;1&lt;/TD&gt;
&lt;TD style="width: 283px; height: 19px;"&gt;LLT&lt;/TD&gt;
&lt;TD style="width: 267px; height: 19px;"&gt;&lt;STRONG&gt;[LLT]&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 19px;"&gt;
&lt;TD style="width: 61px; height: 19px;"&gt;1&lt;/TD&gt;
&lt;TD style="width: 283px; height: 19px;"&gt;).&lt;/TD&gt;
&lt;TD style="width: 267px; height: 19px;"&gt;).&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 39px;"&gt;
&lt;TD style="width: 61px; height: 39px;"&gt;2&lt;/TD&gt;
&lt;TD style="width: 283px; height: 39px;"&gt;Samsung - the first major smartphone maker to release a foldable smartphone&lt;/TD&gt;
&lt;TD style="width: 267px; height: 39px;"&gt;&lt;STRONG&gt;[Samsung - the first major smartphone maker to release a foldable smartphone]&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The solutions provide good start to go ahead.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I can sort of see a potential use for the single "word" brackets, but without a real world description of why that last entire phrase is in [] when everything else is a single "word" I am not going to spend any time trying to parse an incomplete problem description, which&amp;nbsp;was not helped by the earlier examples with the ([LLT]) and ' being included with the brackets.&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 15:08:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-text-based-on-brackets-using-do-loop/m-p/556454#M155013</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-06T15:08:44Z</dc:date>
    </item>
  </channel>
</rss>

