<?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: Extract,identify,split and concatenate in same string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-identify-split-and-concatenate-in-same-string/m-p/530885#M145200</link>
    <description>&lt;P&gt;Thanks for immediate response. But this is not always the same , text differs for each and every iteration , the variables differs and we should also add the quotes for the string before and after identifying the variables.&lt;/P&gt;
&lt;P&gt;the original is what is present in the dataset and output is expected . The text in the output is added with quotes ,pipe symbol is prefixed to concatenate the variable and after that again the text is placed in &amp;nbsp;quoted till the next variables are identified , its repeated till the end of the string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="946"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="413"&gt;Original&amp;nbsp;&lt;/TD&gt;
&lt;TD width="533"&gt;Output&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="413"&gt;It was found that the customer transacted an average of [AVERAGE] transaction per month in [START_YEAR] and closed account in [END_YR]. ;&lt;/TD&gt;
&lt;TD width="533"&gt;"It was found that the customer transacted an average of" || strip(AVERAGE) || "transaction per month in" || strip(START_YEAR) || "and closed account in" || strip(END_YR).";&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
    <pubDate>Tue, 29 Jan 2019 10:04:53 GMT</pubDate>
    <dc:creator>keen_sas</dc:creator>
    <dc:date>2019-01-29T10:04:53Z</dc:date>
    <item>
      <title>Extract,identify,split and concatenate in same string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-identify-split-and-concatenate-in-same-string/m-p/530872#M145198</link>
      <description>&lt;P&gt;The observation consists of text along with the variable names, that variable while concatenating will be converted into value and forms a complete observation. The variable names are embedded &amp;nbsp;in &lt;STRONG&gt;square brackets&lt;/STRONG&gt;. While concatenating they should be stripped to avoid unwanted spaces in the final observation.The number of variables are not fixed , the text may also contain some special characters as well. How to make this functional. Original is the text and output is what is expected,both are displayed below at the end.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tried with the below code.,but something is missing the do loop while splitting the text based on delimiter ']'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a; &lt;BR /&gt;text="It was found that the customer transacted an average of [AVERAGE] transaction per month in [START_YEAR] and closed account in [END_YR]." ;&lt;BR /&gt;call symputx('txt',countw(text,"]")); &lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data b;&lt;BR /&gt;set a ;&lt;BR /&gt;array txt{&amp;amp;txt} $200. ;&lt;BR /&gt;do i = 1 to countw(text,"]"); &lt;BR /&gt;if i =1 then txt{i}=substr(text,1,find(text,"]"));&lt;BR /&gt;else txt{i}=substr(text,find(text,"]")+1,find(text,"]")); &lt;BR /&gt;end;&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="946"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD style="width: 353px;"&gt;Original&amp;nbsp;&lt;/TD&gt;
&lt;TD style="width: 561px;"&gt;Output&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 353px;"&gt;It was found that the customer transacted an average of [AVERAGE] transaction per month in [START_YEAR] and closed account in [END_YR]. ;&lt;/TD&gt;
&lt;TD style="width: 561px;"&gt;"It was found that the customer transacted an average of" || strip(AVERAGE) || "transaction per month in" || strip(START_YEAR) || "and closed account in" || strip(END_YR).";&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2019 09:40:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-identify-split-and-concatenate-in-same-string/m-p/530872#M145198</guid>
      <dc:creator>keen_sas</dc:creator>
      <dc:date>2019-01-29T09:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: Extract,identify,split and concatenate in same string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-identify-split-and-concatenate-in-same-string/m-p/530877#M145199</link>
      <description>&lt;P&gt;Is it always the same?&amp;nbsp; Three tranwrds or regreplaces is the easiest:&lt;/P&gt;
&lt;PRE&gt;data b;
  set a;
  text=tranwrd(text,'[AVERAGE]','"||strip(AVERAGE)||"');
  text=tranwrd(text,'[START_YEAR]','"||strip(START_YEAR)||"');
  text=tranwrd(text,'[END_YR]','"||strip(END_YR)||"');
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Jan 2019 09:47:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-identify-split-and-concatenate-in-same-string/m-p/530877#M145199</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-01-29T09:47:32Z</dc:date>
    </item>
    <item>
      <title>Re: Extract,identify,split and concatenate in same string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-identify-split-and-concatenate-in-same-string/m-p/530885#M145200</link>
      <description>&lt;P&gt;Thanks for immediate response. But this is not always the same , text differs for each and every iteration , the variables differs and we should also add the quotes for the string before and after identifying the variables.&lt;/P&gt;
&lt;P&gt;the original is what is present in the dataset and output is expected . The text in the output is added with quotes ,pipe symbol is prefixed to concatenate the variable and after that again the text is placed in &amp;nbsp;quoted till the next variables are identified , its repeated till the end of the string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="946"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="413"&gt;Original&amp;nbsp;&lt;/TD&gt;
&lt;TD width="533"&gt;Output&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="413"&gt;It was found that the customer transacted an average of [AVERAGE] transaction per month in [START_YEAR] and closed account in [END_YR]. ;&lt;/TD&gt;
&lt;TD width="533"&gt;"It was found that the customer transacted an average of" || strip(AVERAGE) || "transaction per month in" || strip(START_YEAR) || "and closed account in" || strip(END_YR).";&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Tue, 29 Jan 2019 10:04:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-identify-split-and-concatenate-in-same-string/m-p/530885#M145200</guid>
      <dc:creator>keen_sas</dc:creator>
      <dc:date>2019-01-29T10:04:53Z</dc:date>
    </item>
    <item>
      <title>Re: Extract,identify,split and concatenate in same string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-identify-split-and-concatenate-in-same-string/m-p/530897#M145201</link>
      <description>&lt;P&gt;My code does include quotes.&amp;nbsp; If it changes each time, then will the text between angular brackets always be the variable?&amp;nbsp; If so then replace the text&lt;/P&gt;
&lt;P&gt;[ with "||strip(&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;and the text&lt;/P&gt;
&lt;P&gt;] with )||"&lt;/P&gt;
&lt;P&gt;E.g.&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  text=tranwrd('[','"||strip(');
  text=tranwrd(']',')||"');
run;&lt;/PRE&gt;
&lt;P&gt;Note the double quotes used within the replacement strings.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2019 10:17:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-identify-split-and-concatenate-in-same-string/m-p/530897#M145201</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-01-29T10:17:14Z</dc:date>
    </item>
    <item>
      <title>Re: Extract,identify,split and concatenate in same string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-identify-split-and-concatenate-in-same-string/m-p/531029#M145273</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;The observation consists of text along with the variable names, that variable while concatenating will be converted into value and forms a complete observation. The variable names are embedded &amp;nbsp;in &lt;STRONG&gt;square brackets&lt;/STRONG&gt;. While concatenating they should be stripped to avoid unwanted spaces in the final observation.The number of variables are not fixed , the text may also contain some special characters as well. How to make this functional. Original is the text and output is what is expected,both are displayed below at the end.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tried with the below code.,but something is missing the do loop while splitting the text based on delimiter ']'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a; &lt;BR /&gt;text="It was found that the customer transacted an average of [AVERAGE] transaction per month in [START_YEAR] and closed account in [END_YR]." ;&lt;BR /&gt;call symputx('txt',countw(text,"]")); &lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data b;&lt;BR /&gt;set a ;&lt;BR /&gt;array txt{&amp;amp;txt} $200. ;&lt;BR /&gt;do i = 1 to countw(text,"]"); &lt;BR /&gt;if i =1 then txt{i}=substr(text,1,find(text,"]"));&lt;BR /&gt;else txt{i}=substr(text,find(text,"]")+1,find(text,"]")); &lt;BR /&gt;end;&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="946"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD style="width: 353px;"&gt;Original&amp;nbsp;&lt;/TD&gt;
&lt;TD style="width: 561px;"&gt;Output&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 353px;"&gt;It was found that the customer transacted an average of [AVERAGE] transaction per month in [START_YEAR] and closed account in [END_YR]. ;&lt;/TD&gt;
&lt;TD style="width: 561px;"&gt;"It was found that the customer transacted an average of" || strip(AVERAGE) || "transaction per month in" || strip(START_YEAR) || "and closed account in" || strip(END_YR).";&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why are you requiring the use of the || operator? And how is the "output" variable used?&lt;/P&gt;
&lt;P&gt;I&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2019 15:51:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-identify-split-and-concatenate-in-same-string/m-p/531029#M145273</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-01-29T15:51:03Z</dc:date>
    </item>
  </channel>
</rss>

