<?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: Checking an array for not empty in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Checking-an-array-for-not-empty/m-p/347060#M80109</link>
    <description>&lt;P&gt;&lt;STRONG&gt;Post test data in the form of a datastep.&amp;nbsp;&lt;/STRONG&gt; &amp;nbsp;This really helps illustrate your problem. &amp;nbsp;At a guess, you could just concat the array and check for length?&lt;/P&gt;
&lt;PRE&gt;if lengthn(cats(of hd_;)) &amp;gt; 0 then output;&lt;/PRE&gt;
&lt;P&gt;I.e. if they are all blanks lengthn=0 so no output.&lt;/P&gt;</description>
    <pubDate>Tue, 04 Apr 2017 14:55:36 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-04-04T14:55:36Z</dc:date>
    <item>
      <title>Checking an array for not empty</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-an-array-for-not-empty/m-p/347054#M80104</link>
      <description>&lt;P&gt;I have a dataset of hospital discharges for 57&amp;nbsp;months (hd1-hd57) with character values (up to 20 in length) if there was a discharge. I want to select the records that have values. I wrote this code but it is not selecting all the records:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data kids_case;&lt;BR /&gt;set casemix_&lt;SPAN&gt;cancer&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array hd(57) cancer_HD1-&lt;SPAN&gt;cancer&lt;/SPAN&gt;_HD57;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; do i=1 to dim(hd);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; date_hd=hd(i);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if missing(date_hd) then &lt;SPAN&gt;cancer&lt;/SPAN&gt;_hd=0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; else &lt;SPAN&gt;cancer&lt;/SPAN&gt;_hd=1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if &lt;SPAN&gt;cancer&lt;/SPAN&gt;_hd=1;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the data is in this format&lt;/P&gt;
&lt;P&gt;id $20, &lt;SPAN&gt;cancer&lt;/SPAN&gt;&lt;SPAN&gt;_HD1-&lt;/SPAN&gt;&lt;SPAN&gt;cancer&lt;/SPAN&gt;&lt;SPAN&gt;_HD57 $20&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So, one record has id=XXHGG and only has 2 discharges: cancer_HD1=2345 and cancer_HD45=58414528. The rest of cancer_HD are blanks.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2017 14:36:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-an-array-for-not-empty/m-p/347054#M80104</guid>
      <dc:creator>malena</dc:creator>
      <dc:date>2017-04-04T14:36:09Z</dc:date>
    </item>
    <item>
      <title>Re: Checking an array for not empty</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-an-array-for-not-empty/m-p/347060#M80109</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Post test data in the form of a datastep.&amp;nbsp;&lt;/STRONG&gt; &amp;nbsp;This really helps illustrate your problem. &amp;nbsp;At a guess, you could just concat the array and check for length?&lt;/P&gt;
&lt;PRE&gt;if lengthn(cats(of hd_;)) &amp;gt; 0 then output;&lt;/PRE&gt;
&lt;P&gt;I.e. if they are all blanks lengthn=0 so no output.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2017 14:55:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-an-array-for-not-empty/m-p/347060#M80109</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-04T14:55:36Z</dc:date>
    </item>
    <item>
      <title>Re: Checking an array for not empty</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-an-array-for-not-empty/m-p/347061#M80110</link>
      <description>&lt;P&gt;The code you have tests all values in the array. The value of &lt;SPAN&gt;cancer&lt;/SPAN&gt;_hd is always going to be the result of the last comparison after the do loop.&lt;/P&gt;
&lt;P&gt;If you want to set cancer_hd=1 when any of the values are set then perhaps this is what you want;&lt;/P&gt;
&lt;PRE&gt;data kids_case;
   set casemix_cancer;
   array hd(57) cancer_HD1-cancer_HD57;
   do i=1 to dim(hd);
      date_hd=hd(i);
      if missing(date_hd) then cancer_hd=0;
      else do;
         cancer_hd=1;
         leave;
      end;
   end;
   if cancer_hd=1;
run;&lt;/PRE&gt;
&lt;P&gt;The LEAVE statement says to quit the do loop when encountered. So this will interupt the loop the first time if finds a non-missing value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2017 14:56:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-an-array-for-not-empty/m-p/347061#M80110</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-04-04T14:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: Checking an array for not empty</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-an-array-for-not-empty/m-p/347062#M80111</link>
      <description>&lt;P&gt;Your logic is flawed. You should set the flag to false before the loop and then in the loop set it to true if any non missing value is found. &amp;nbsp;Your current code is effectly only testing the last value in the array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But why not just use the CMISS() function to count how many variables have a missing value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; cancer_hd = not (57 = cmiss(of cancerHD1-cancer_HD57));
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Apr 2017 14:56:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-an-array-for-not-empty/m-p/347062#M80111</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-04-04T14:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: Checking an array for not empty</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-an-array-for-not-empty/m-p/347063#M80112</link>
      <description>&lt;P&gt;Just to select the entire record, you could use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data kids_case;&lt;/P&gt;
&lt;P&gt;set casemix_cancer;&lt;/P&gt;
&lt;P&gt;if cat(of cancer_hd1 - cancer_hd57) &amp;gt; ' ';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are trying to take the existing records and find only the nonblank discharges, that would take a different approach.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2017 14:56:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-an-array-for-not-empty/m-p/347063#M80112</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-04T14:56:51Z</dc:date>
    </item>
    <item>
      <title>Re: Checking an array for not empty</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-an-array-for-not-empty/m-p/347074#M80117</link>
      <description>&lt;P&gt;thank you for all your suggestions! really appreciate it all your help&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2017 15:20:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-an-array-for-not-empty/m-p/347074#M80117</guid>
      <dc:creator>malena</dc:creator>
      <dc:date>2017-04-04T15:20:42Z</dc:date>
    </item>
  </channel>
</rss>

