<?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: concatenate non missing values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/concatenate-non-missing-values/m-p/375351#M89974</link>
    <description>&lt;P&gt;To work with the nonmissing values only, you will need to write a little code.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;array x {5};&lt;/P&gt;
&lt;P&gt;length ch $ 20;&lt;/P&gt;
&lt;P&gt;do _n_=1 to 5;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if x{_n_} &amp;gt; . then ch = catx('-', ch, x{_n_});&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jul 2017 15:06:49 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-07-12T15:06:49Z</dc:date>
    <item>
      <title>concatenate non missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-non-missing-values/m-p/375341#M89968</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have data as below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data x;&lt;BR /&gt;input x1 x2 x3 x4 x5;&lt;BR /&gt;datalines;&lt;BR /&gt;1 2 3 4 5&lt;BR /&gt;. 2 3 4 5&lt;BR /&gt;1 . 3 4 5&lt;BR /&gt;1 2 . 4 5&lt;BR /&gt;. . 3 4 .&lt;BR /&gt;. . . . 5&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;I want to concatenate all this non missing values only.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Final output should contain all non missing values seperated by "-".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have used below function but didnt work for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ch=catx("-",of x1-x5);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone please help me here ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 14:49:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-non-missing-values/m-p/375341#M89968</guid>
      <dc:creator>draroda</dc:creator>
      <dc:date>2017-07-12T14:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate non missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-non-missing-values/m-p/375345#M89970</link>
      <description>&lt;P&gt;Show the code that didn't work and what you want as output.&lt;/P&gt;
&lt;P&gt;AFAIK the solution should be CATX.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 14:52:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-non-missing-values/m-p/375345#M89970</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-12T14:52:59Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate non missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-non-missing-values/m-p/375351#M89974</link>
      <description>&lt;P&gt;To work with the nonmissing values only, you will need to write a little code.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;array x {5};&lt;/P&gt;
&lt;P&gt;length ch $ 20;&lt;/P&gt;
&lt;P&gt;do _n_=1 to 5;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if x{_n_} &amp;gt; . then ch = catx('-', ch, x{_n_});&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 15:06:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-non-missing-values/m-p/375351#M89974</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-12T15:06:49Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate non missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-non-missing-values/m-p/375359#M89978</link>
      <description>&lt;P&gt;Please look at this:&lt;/P&gt;
&lt;PRE&gt;options missing=' ';
data work.junk;
input x1 x2 x3 x4 x5;
ch=catx("-",of x1-x5);
datalines;
1 2 3 4 5
. 2 3 4 5
1 . 3 4 5
1 2 . 4 5
. . 3 4 .
. . . . 5
;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you values are numeric then by default the missing value is returned for the CATX function when the numbers are turned into strings to concatenate. Changing the option missing to a blank character means allows CATX to strip the "blanks".&lt;/P&gt;
&lt;P&gt;Don't forget to reset the Option after the data step this is needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"didnt work for me" is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of a dataset, the actual results and the expected results. Data should be in the form of a data step. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat&lt;/A&gt;... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 15:13:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-non-missing-values/m-p/375359#M89978</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-07-12T15:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate non missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-non-missing-values/m-p/375361#M89980</link>
      <description>&lt;P&gt;It seems CATX will deal with missing characters properly, but when it converts the numeric to character it becomes a period which is no longer a 'missing' value. IMO this is not the expected behaviour though it does line up with the documentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;The CATX function first copies&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="xis-userSuppliedValue"&gt;item-1&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;to the result, omitting leading and trailing blanks. Then for each subsequent argument&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="xis-userSuppliedValue"&gt;item-i&lt;/SPAN&gt;&lt;SPAN&gt;, i=2, …, n, &lt;STRONG&gt;if&amp;nbsp;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN class="xis-userSuppliedValue"&gt;item-i&lt;/SPAN&gt;&amp;nbsp;contains at least one non-blank character, then CATX appends&amp;nbsp;&lt;SPAN class="xis-userSuppliedValue"&gt;delimiter&lt;/SPAN&gt;and&amp;nbsp;&lt;SPAN class="xis-userSuppliedValue"&gt;item-i&lt;/SPAN&gt;&amp;nbsp;to the result, omitting leading and trailing blanks from&amp;nbsp;&lt;SPAN class="xis-userSuppliedValue"&gt;item-i&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;&lt;STRONG&gt;.&lt;/STRONG&gt; CATX does not insert the delimiter at the beginning or end of the result. &lt;STRONG&gt;Blank items do not produce delimiters at the beginning or end of the result, nor do blank items produce multiple consecutive delimiters.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;&amp;nbsp;If&amp;nbsp;&lt;SPAN class="xis-userSuppliedValue"&gt;item&lt;/SPAN&gt;&amp;nbsp;is numeric, then its value is converted to a character string by using the BEST&lt;SPAN class="xis-userSuppliedValue"&gt;w&lt;/SPAN&gt;. format.&lt;/FONT&gt; In this case, SAS does not write a note to the log. For more information, see&amp;nbsp;&lt;SPAN class="xis-xrefSee"&gt;&lt;A title="" href="http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/n0p7wxtk0hvn83n1pveisbcp2ae9.htm#p0prhxaj29aqfqn1hqtd1b8p2pi0" target="_blank"&gt;The Basics&lt;/A&gt;&lt;/SPAN&gt;.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Various solutions include:&lt;/P&gt;
&lt;P&gt;1. Read in as character instead of numeric&lt;/P&gt;
&lt;P&gt;2. Loop (see&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;solution).&lt;/P&gt;
&lt;P&gt;3. Set option missing to a blank instead of ., see below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options missing='';
data x;
input x1 x2 x3 x4 x5;
want = catx('-', of x1-x5);
datalines;
1 2 3 4 5
. 2 3 4 5
1 . 3 4 5
1 2 . 4 5
. . 3 4 .
. . . . 5
;
run;
options missing=.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 15:14:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-non-missing-values/m-p/375361#M89980</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-12T15:14:11Z</dc:date>
    </item>
  </channel>
</rss>

