<?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: Find first 5 non missing character values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-first-5-non-missing-character-values/m-p/665619#M199065</link>
    <description>&lt;P&gt;Here how this could work using arrays (code not tested). I've set the length in array name to $20 - set here the same length than what your Level variables got.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=_:);
  set test;
  array levels {*} level1 - level22;
  array name {5} $20;
  do _i=dim(levels) to 1 by -1;
    if not missing(levels[_i]) then
      do;
        _k=sum(_k,1);
        name[_k]=levels[_i];
        if _k=5 then leave;
      end;
  end;
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 28 Jun 2020 07:14:42 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2020-06-28T07:14:42Z</dc:date>
    <item>
      <title>Find first 5 non missing character values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-first-5-non-missing-character-values/m-p/665610#M199060</link>
      <description>&lt;P&gt;I have a dataset with 22 different character variables named level1-level22.&amp;nbsp; Starting from level22 I would like to search for the first variable that is not missing and then create a new variable using that value called name1 and then do the same for the next non missing variable and create a variable with that value as name2 and so forth.&amp;nbsp; I would like to get the first 5 non missing values so I would like to have the new variables name1-name5 with the first non missing values in order from level22-1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I believe that using an array is my best bet and I am fairly new at SAS arrays so this is what I have so far.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set test;
	array value pos_name_22-pos_name_1;
	array t(*) POS_NAME_22-POS_NAME_1;
	first = coalescec(of pos_name_22-pos_name_1);
	index = whichn(first, of value[*]);

	do _n_=1 to dim(t);
		if missing(t(_n_)) then
			t(_n_)=coalescec(of t(*));
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Jun 2020 05:39:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-first-5-non-missing-character-values/m-p/665610#M199060</guid>
      <dc:creator>nbwest76</dc:creator>
      <dc:date>2020-06-28T05:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: Find first 5 non missing character values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-first-5-non-missing-character-values/m-p/665612#M199062</link>
      <description>&lt;P&gt;No array or loop needed for just 5 values.&lt;/P&gt;
&lt;P&gt;Regardless, this works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  NAME1=scan(catx(' ',of LEVEL1-LEVEL22),-1);
  NAME2=scan(catx(' ',of LEVEL1-LEVEL22),-2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Keep things simple!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Jun 2020 06:35:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-first-5-non-missing-character-values/m-p/665612#M199062</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-06-28T06:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: Find first 5 non missing character values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-first-5-non-missing-character-values/m-p/665619#M199065</link>
      <description>&lt;P&gt;Here how this could work using arrays (code not tested). I've set the length in array name to $20 - set here the same length than what your Level variables got.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=_:);
  set test;
  array levels {*} level1 - level22;
  array name {5} $20;
  do _i=dim(levels) to 1 by -1;
    if not missing(levels[_i]) then
      do;
        _k=sum(_k,1);
        name[_k]=levels[_i];
        if _k=5 then leave;
      end;
  end;
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Jun 2020 07:14:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-first-5-non-missing-character-values/m-p/665619#M199065</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-06-28T07:14:42Z</dc:date>
    </item>
    <item>
      <title>Re: Find first 5 non missing character values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-first-5-non-missing-character-values/m-p/665648#M199071</link>
      <description>&lt;P&gt;And what to you expect when there are fewer than 5 non-missing values?&lt;/P&gt;</description>
      <pubDate>Sun, 28 Jun 2020 17:23:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-first-5-non-missing-character-values/m-p/665648#M199071</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-28T17:23:26Z</dc:date>
    </item>
  </channel>
</rss>

