<?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: Dynamic concatenation in dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-concatenation-in-dataset/m-p/569708#M160587</link>
    <description>Thank you Tom for your quick response. For your questions 1) In case if any  delimiter is specified , we have to use CATx instead of CATs, so to avoid this change using CATx.&lt;BR /&gt;2) Its the specification provided by the team ,its mandatory to use, cannot avoid it.</description>
    <pubDate>Fri, 28 Jun 2019 06:36:58 GMT</pubDate>
    <dc:creator>keen_sas</dc:creator>
    <dc:date>2019-06-28T06:36:58Z</dc:date>
    <item>
      <title>Dynamic concatenation in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-concatenation-in-dataset/m-p/569411#M160461</link>
      <description>&lt;P&gt;There are few variables along with some text provided in spreadsheet or in another dataset. The task is to concatenate the variables along with the text in that particular dataset. Before calling the specified condition into the required dataset to concatenate , it has to be converted into proper SAS syntax/algorthim to make it work as mentioned below. I am using &lt;STRONG&gt;sashelp.svrtdist&amp;nbsp; to test this.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="width: 799px;" width="901"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD style="width: 40px;"&gt;S.No&lt;/TD&gt;
&lt;TD style="width: 286px;"&gt;&lt;STRONG&gt;Original (Have)&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD style="width: 427px;"&gt;&lt;STRONG&gt;SAS Algorthim to make it work (WANT)&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 40px;"&gt;1&lt;/TD&gt;
&lt;TD style="width: 286px;"&gt;type " (" subtype name ")"&lt;/TD&gt;
&lt;TD style="width: 427px;"&gt;catx('',type, " (", subtype, name, ")" );&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 40px;"&gt;2&lt;/TD&gt;
&lt;TD style="width: 286px;"&gt;&amp;nbsp;(' type&amp;nbsp; sequence&amp;nbsp; name ')'&lt;/TD&gt;
&lt;TD style="width: 427px;"&gt;catx('',' (', type, sequence, name, ')') ;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 40px;"&gt;3&lt;/TD&gt;
&lt;TD style="width: 286px;"&gt;type " combination of type and subtype (" subtype name ")"&lt;/TD&gt;
&lt;TD style="width: 427px;"&gt;catx('',type, " combination of type and subtype (", subtype, name ")");&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 40px;"&gt;4&lt;/TD&gt;
&lt;TD style="width: 286px;"&gt;type " (" subtype ")"&amp;nbsp; ' - ' name&amp;nbsp;&lt;/TD&gt;
&lt;TD style="width: 427px;"&gt;catx('',type, " (",subtype,")", '-', name);&amp;nbsp;&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;%macro test ;&lt;BR /&gt;data text ;&lt;BR /&gt;length have $50.;&lt;BR /&gt;have='type " (" subtype name ")"';output;&lt;BR /&gt;have="'(' type sequence name ')'";output;&lt;BR /&gt;have="type 'combination of type and subtype (' name ')' ";output ;&lt;BR /&gt;have='type " - " subtype name' ;output ;&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data text ;&lt;BR /&gt;set text ;&lt;BR /&gt;if not missing(have) then want="catx('',"||tranwrd(strip(have),' ' ,',') ||');' ;&lt;BR /&gt;call symputx('cnt',_n_) ;&lt;BR /&gt;call symputx (cats("cond",_n_),want) ;&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test;&lt;BR /&gt;set sashelp.svrtdist (keep=type subtype name sequence owner);&lt;BR /&gt;%do i =1 %to &amp;amp;cnt;&lt;BR /&gt;want&amp;amp;i=&amp;amp;&amp;amp;cond&amp;amp;i ;&lt;BR /&gt;%end;&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;%mend test ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%test ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Type, subtype, name are the variables present in SASHELP.SVRTDIST dataset and the condition what to concatenate are placed in TEXT&amp;nbsp; dataset with HAVE as variable . To concatenate these variables i have to convert them into SAS acceptable syntax as present in another column WANT as shown above.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) The issue with this is &lt;STRONG&gt;" (" and ' - '&lt;/STRONG&gt; since there is a space between quote and ", this &lt;STRONG&gt;space is also converting into comma,&lt;/STRONG&gt; which should not be done. The string present between the quotes is having spaces between the words, these sapces also converted to commas.&lt;/P&gt;
&lt;P&gt;2) After concatenation there should not be any space between the parenthesis like&amp;nbsp;&lt;STRONG&gt;Header ( Package ), it should be like Header(Package).&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;is there any easier method/alternative approach to make this concatenation work in the dataset in dynamic way without any manual intervention.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 13:06:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-concatenation-in-dataset/m-p/569411#M160461</guid>
      <dc:creator>keen_sas</dc:creator>
      <dc:date>2019-06-27T13:06:16Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic concatenation in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-concatenation-in-dataset/m-p/569678#M160574</link>
      <description>Hello, if it's about dealing with the blanks, can't you use COMPBL (Compress Blanks) function?</description>
      <pubDate>Fri, 28 Jun 2019 00:33:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-concatenation-in-dataset/m-p/569678#M160574</guid>
      <dc:creator>karan124</dc:creator>
      <dc:date>2019-06-28T00:33:02Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic concatenation in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-concatenation-in-dataset/m-p/569693#M160582</link>
      <description>&lt;P&gt;Two questions.&lt;/P&gt;
&lt;P&gt;1) Why are you using CATX() instead of CATS() if you don't actually include anything to insert between the values?&lt;/P&gt;
&lt;P&gt;2) Why are you storing the strings in the dataset with spaces as the delimiter if you need to use them with commas as the delimiter?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The easiest way to convert the delimiters in a list is to parse the list and re-create it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data text;
  input id have $50.;
cards;
1	type " (" subtype name ")"	
2	'(' type  sequence  name ')'
3	type " combination of type and subtype (" subtype name ")"	
4	type " (" subtype ")"  ' - ' name
;

data fix ;
  set text;
  length code $200 ;
  do i=1 to countw(have,' ','q');
     code=catx(',',code,scan(have,i,' ','q'));
  end;
  code=cats("catx(' ',",code,')');
  drop i;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    id    have

 1      1    type " (" subtype name ")"
 2      2    '(' type  sequence  name ')'
 3      3    type " combination of type and subtype (" subtype
 4      4    type " (" subtype ")"  ' - ' name

Obs    code

 1     catx(' ',type," (",subtype,name,")")
 2     catx(' ','(',type,sequence,name,')')
 3     catx(' ',type," combination of type and subtype (",subtype)
 4     catx(' ',type," (",subtype,")",' - ',name)&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Jun 2019 03:47:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-concatenation-in-dataset/m-p/569693#M160582</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-28T03:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic concatenation in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-concatenation-in-dataset/m-p/569708#M160587</link>
      <description>Thank you Tom for your quick response. For your questions 1) In case if any  delimiter is specified , we have to use CATx instead of CATs, so to avoid this change using CATx.&lt;BR /&gt;2) Its the specification provided by the team ,its mandatory to use, cannot avoid it.</description>
      <pubDate>Fri, 28 Jun 2019 06:36:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-concatenation-in-dataset/m-p/569708#M160587</guid>
      <dc:creator>keen_sas</dc:creator>
      <dc:date>2019-06-28T06:36:58Z</dc:date>
    </item>
  </channel>
</rss>

