<?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: conditional concatenation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/conditional-concatenation/m-p/555653#M154644</link>
    <description>&lt;P&gt;I will say unless this purely an exercise in programming logic that the output is problematic at best and potentially quite misleading.&lt;/P&gt;
&lt;P&gt;Consider if an output is :&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;The details of the student are John and 80. &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;How do you know whether the 80 represents age, height or weight (given data similar to SASHELP.CLASS)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your actual data does not have any actual missing values that is one thing but random values without context when there are missing is very odd.&lt;/P&gt;</description>
    <pubDate>Thu, 02 May 2019 16:38:03 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-05-02T16:38:03Z</dc:date>
    <item>
      <title>conditional concatenation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-concatenation/m-p/555551#M154614</link>
      <description>&lt;P&gt;I have string with variable names and text embedded in it and all variable names are embedded in square brackets. While concatenating&lt;BR /&gt;need to cross check the result values present in the variable. In case of multiple results, these should be concatenated using comma&amp;nbsp; (addition of “and” before the last entry only). Variables are combination of character and numeric.&lt;/P&gt;
&lt;P&gt;For example If A , B present then concatenation should be A and B. If 3 results are present result should be A, B and C .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;&lt;EM&gt;text="The details of the student are (values=[NAME] [SEX] [AGE] [HEIGHT] [WEIGHT]).";&lt;/EM&gt;&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data class;&lt;BR /&gt;set sashelp.class;&lt;BR /&gt;/* scenarios to be considered*/&lt;BR /&gt;if name="Alice" then do ;call missing(height,weight);end;&lt;BR /&gt;if name="John" then do ; call missing(sex,age);end;&lt;BR /&gt;if name="Carol" then do ; call missing(age, height, weight) ;end;&lt;BR /&gt;ab=catx(',',name,sex, age, height, weight) ; &lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output should be as below.&lt;BR /&gt;&lt;STRONG&gt;The details of the student are Alfred,F,14,69 and 12.5. &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;The details of the student are John,59 and 99.5. &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;The details of the student are Carol and F.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Any suggestion or sample code how to get the required output.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 09:50:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-concatenation/m-p/555551#M154614</guid>
      <dc:creator>keen_sas</dc:creator>
      <dc:date>2019-05-02T09:50:14Z</dc:date>
    </item>
    <item>
      <title>Re: conditional concatenation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-concatenation/m-p/555567#M154621</link>
      <description>&lt;P&gt;I have amended an extra row for William and assumed missing is set to '.'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options missing = ' ';

data have;
   set sashelp.class;
   /* scenarios to be considered*/
   if name="Alice" then do ;call missing(height,weight);end;
   if name="John" then do ; call missing(sex,age);end;
   if name="Carol" then do ; call missing(age, height, weight) ;end;
   if name="William" then do ; call missing(sex, age, height, weight) ;end;
   ab=catx(',',name,sex, age, height, weight) ; 
run ;


data want;
   set have;

   length text   $ 100
          values $ 100
   ;

   values = catx(',',name,sex,age,height,weight);

   pos    = find(values,',',-length(strip(values)));

   if pos then
      values = catx(' ',substr(values,1,pos-1),'and',substr(values,pos+1));

   text = cat('The details of the students are ',strip(values),'.');
run;

options missing = '.';&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 11:26:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-concatenation/m-p/555567#M154621</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-05-02T11:26:19Z</dc:date>
    </item>
    <item>
      <title>Re: conditional concatenation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-concatenation/m-p/555653#M154644</link>
      <description>&lt;P&gt;I will say unless this purely an exercise in programming logic that the output is problematic at best and potentially quite misleading.&lt;/P&gt;
&lt;P&gt;Consider if an output is :&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;The details of the student are John and 80. &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;How do you know whether the 80 represents age, height or weight (given data similar to SASHELP.CLASS)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your actual data does not have any actual missing values that is one thing but random values without context when there are missing is very odd.&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 16:38:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-concatenation/m-p/555653#M154644</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-02T16:38:03Z</dc:date>
    </item>
  </channel>
</rss>

