<?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: how to apply delimiter based on condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-apply-delimiter-based-on-condition/m-p/815244#M321792</link>
    <description>&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/60547"&gt;@sbxkoenk&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code will result as&amp;nbsp;" , MN, QR&lt;SPAN&gt;ST" but I need&amp;nbsp;MN, QRST. I don't want additional "," when data is empty. Please refer desired output value.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 26 May 2022 15:59:10 GMT</pubDate>
    <dc:creator>1239</dc:creator>
    <dc:date>2022-05-26T15:59:10Z</dc:date>
    <item>
      <title>how to apply delimiter based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-apply-delimiter-based-on-condition/m-p/815227#M321782</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to apply delimiter (",") only when data is present in A and B but not for C, D and E variables. I am trying the below code but unable to achieve the desired output values. Kindly refer below SAS code, input data (.csv file attached) and desire output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help me in achieving the desired output value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data need;
set have;
V = cats(V1, ",", V2, ",", V3, V4, V5);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Input data:&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 240pt;" border="0" width="320px" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD width="63.8px" height="14px" class="xl65" style="height: 14.4pt; width: 48pt;"&gt;&lt;STRONG&gt;A&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="63.8px" height="14px" class="xl65" style="border-left: none; width: 48pt;"&gt;&lt;STRONG&gt;B&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="63.8px" height="14px" class="xl65" style="border-left: none; width: 48pt;"&gt;&lt;STRONG&gt;C&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="63.8px" height="14px" class="xl65" style="border-left: none; width: 48pt;"&gt;&lt;STRONG&gt;D&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="63.8px" height="14px" class="xl65" style="border-left: none; width: 48pt;"&gt;&lt;STRONG&gt;E&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD width="63.8px" height="14px" class="xl66" style="height: 14.4pt; border-top: none;"&gt;AB&lt;/TD&gt;
&lt;TD width="63.8px" height="14px" class="xl66" style="border-top: none; border-left: none;"&gt;CD&lt;/TD&gt;
&lt;TD width="63.8px" height="14px" class="xl66" style="border-top: none; border-left: none;"&gt;EF&lt;/TD&gt;
&lt;TD width="63.8px" height="14px" class="xl66" style="border-top: none; border-left: none;"&gt;GH&lt;/TD&gt;
&lt;TD width="63.8px" height="14px" class="xl66" style="border-top: none; border-left: none;"&gt;IJ&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD width="63.8px" height="14px" class="xl66" style="height: 14.4pt; border-top: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.8px" height="14px" class="xl66" style="border-top: none; border-left: none;"&gt;MN&lt;/TD&gt;
&lt;TD width="63.8px" height="14px" class="xl66" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.8px" height="14px" class="xl66" style="border-top: none; border-left: none;"&gt;QR&lt;/TD&gt;
&lt;TD width="63.8px" height="14px" class="xl66" style="border-top: none; border-left: none;"&gt;ST&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD width="63.8px" height="14px" class="xl66" style="height: 14.4pt; border-top: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.8px" height="14px" class="xl66" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.8px" height="14px" class="xl66" style="border-top: none; border-left: none;"&gt;EF&lt;/TD&gt;
&lt;TD width="63.8px" height="14px" class="xl66" style="border-top: none; border-left: none;"&gt;GH&lt;/TD&gt;
&lt;TD width="63.8px" height="14px" class="xl66" style="border-top: none; border-left: none;"&gt;IJ&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD width="63.8px" height="14px" class="xl66" style="height: 14.4pt; border-top: none;"&gt;AB&lt;/TD&gt;
&lt;TD width="63.8px" height="14px" class="xl66" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.8px" height="14px" class="xl66" style="border-top: none; border-left: none;"&gt;EF&lt;/TD&gt;
&lt;TD width="63.8px" height="14px" class="xl66" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.8px" height="14px" class="xl66" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="173px"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="172px"&gt;&lt;STRONG&gt;desired output value&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="172px"&gt;AB, CD, EFGHIJ&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="172px"&gt;MN, QRST&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="172px"&gt;EFGHIJ&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="172px"&gt;AB, EF&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2022 14:34:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-apply-delimiter-based-on-condition/m-p/815227#M321782</guid>
      <dc:creator>1239</dc:creator>
      <dc:date>2022-05-26T14:34:12Z</dc:date>
    </item>
    <item>
      <title>Re: how to apply delimiter based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-apply-delimiter-based-on-condition/m-p/815229#M321784</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
LENGTH A B C D E $ 2;
infile datalines delimiter='#';
input A $ B	$ C	$ D $ E $;
datalines;
AB	#CD	# EF #GH #IJ
 	#MN	#    #QR #ST
 	# 	# EF #GH #IJ
AB	# 	# EF # 	 # 
;
run;

data want;
 LENGTH concat1 $ 10 concat2 $ 10 concat $ 20;
 set have;
 sp1=', ';
 sp2='@';
 concat1 = CATX(SP1, A, B);
 concat2 = CATX(SP2, C, D, E);
 if strip(concat1) ^= '' then do; concat = strip(concat1)!!', '!!strip(concat2); end;
 else                         do; concat = strip(concat2);                       end;
 concat=compress(concat,'@');
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 May 2022 14:55:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-apply-delimiter-based-on-condition/m-p/815229#M321784</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2022-05-26T14:55:16Z</dc:date>
    </item>
    <item>
      <title>Re: how to apply delimiter based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-apply-delimiter-based-on-condition/m-p/815230#M321785</link>
      <description>&lt;P&gt;Nested function calls.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; catx(', ' , V1, V2, cats(of v3-v5))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do you really want the space after the comma in the result? Why?&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2022 14:51:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-apply-delimiter-based-on-condition/m-p/815230#M321785</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-26T14:51:51Z</dc:date>
    </item>
    <item>
      <title>Re: how to apply delimiter based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-apply-delimiter-based-on-condition/m-p/815244#M321792</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/60547"&gt;@sbxkoenk&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code will result as&amp;nbsp;" , MN, QR&lt;SPAN&gt;ST" but I need&amp;nbsp;MN, QRST. I don't want additional "," when data is empty. Please refer desired output value.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2022 15:59:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-apply-delimiter-based-on-condition/m-p/815244#M321792</guid>
      <dc:creator>1239</dc:creator>
      <dc:date>2022-05-26T15:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: how to apply delimiter based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-apply-delimiter-based-on-condition/m-p/815250#M321793</link>
      <description>&lt;P&gt;Please show example data where you are getting extra comma.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input (A B C D E) ($);
cards;
AB CD EF GH IJ
 . MN  . QR ST
 .  . EF GH IJ
AB  . EF  .  .
;

data want;
 set have;
 length string $20;
 string=catx(',',a,b,cats(c,d,e));
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1653581266726.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71797i3EFE0BC92D5C1349/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1653581266726.png" alt="Tom_0-1653581266726.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2022 16:07:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-apply-delimiter-based-on-condition/m-p/815250#M321793</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-26T16:07:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to apply delimiter based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-apply-delimiter-based-on-condition/m-p/815295#M321802</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19799"&gt;@1239&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm sorry but it's not correct what you say. There's no extra comma.&lt;/P&gt;
&lt;P&gt;See here a PROC PRINT output of the dataset WANT that I produce :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sbxkoenk_0-1653588881555.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71801i5134D593DEDCAF1C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sbxkoenk_0-1653588881555.png" alt="sbxkoenk_0-1653588881555.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2022 18:15:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-apply-delimiter-based-on-condition/m-p/815295#M321802</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2022-05-26T18:15:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to apply delimiter based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-apply-delimiter-based-on-condition/m-p/815334#M321822</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/60547"&gt;@sbxkoenk&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;Please see the PROC PRINT below and extra "," is present in obs = 2 and 3.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1239_0-1653623790903.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71810i71515E8C98EB2CE7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="1239_0-1653623790903.png" alt="1239_0-1653623790903.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
LENGTH A B C D E $ 2;
infile datalines delimiter='#';
input A $ B	$ C	$ D $ E $;
datalines;
AB	#CD	# EF #GH #IJ
 	#MN	#    #QR #ST
 	# 	# EF #GH #IJ
AB	# 	# EF # 	 # 
;
run;

data want;
 LENGTH concat1 $ 10 concat2 $ 10 concat $ 20;
 set have;
 sp1=', ';
 sp2='@';
 concat1 = CATX(SP1, A, B);
 concat2 = CATX(SP2, C, D, E);
 if strip(concat1) ^= '' then do; concat = strip(concat1)!!', '!!strip(concat2); end;
 else                         do; concat = strip(concat2);                       end;
 concat=compress(concat,'@');
run;

proc print data= want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2022 03:58:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-apply-delimiter-based-on-condition/m-p/815334#M321822</guid>
      <dc:creator>1239</dc:creator>
      <dc:date>2022-05-27T03:58:44Z</dc:date>
    </item>
    <item>
      <title>Re: how to apply delimiter based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-apply-delimiter-based-on-condition/m-p/815337#M321823</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code works now and earlier it didn't work because that I was trying your code and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/60547"&gt;@sbxkoenk&lt;/a&gt;&amp;nbsp;code and dataset names were same.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your help!&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1239_1-1653624008682.png" style="width: 337px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71812i1F2C02F4A5D73F82/image-dimensions/337x142?v=v2" width="337" height="142" role="button" title="1239_1-1653624008682.png" alt="1239_1-1653624008682.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2022 04:01:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-apply-delimiter-based-on-condition/m-p/815337#M321823</guid>
      <dc:creator>1239</dc:creator>
      <dc:date>2022-05-27T04:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: how to apply delimiter based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-apply-delimiter-based-on-condition/m-p/815363#M321836</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19799"&gt;@1239&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's very weird. I do not have that extra comma when running that code (my code).&lt;/P&gt;
&lt;P&gt;I use SAS 9.4 M7 (Maintenance Level 7).&lt;/P&gt;
&lt;P&gt;Maybe you run another version (?).&lt;BR /&gt;Or maybe your values are not really missing, ... instead of "nothing" you may have spaces (??).&lt;BR /&gt;I can probably find the root cause for the difference, but since you already have the solution, I'm not going to break my head about it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ciao,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2022 10:05:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-apply-delimiter-based-on-condition/m-p/815363#M321836</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2022-05-27T10:05:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to apply delimiter based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-apply-delimiter-based-on-condition/m-p/815378#M321840</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/60547"&gt;@sbxkoenk&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I use SAS 9.4 M6.&amp;nbsp;&lt;/SPAN&gt;Thanks for all your help and I appreciate it!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2022 10:35:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-apply-delimiter-based-on-condition/m-p/815378#M321840</guid>
      <dc:creator>1239</dc:creator>
      <dc:date>2022-05-27T10:35:35Z</dc:date>
    </item>
  </channel>
</rss>

