<?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: Missing Values Statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Missing-Values-Statement/m-p/511067#M137527</link>
    <description>&lt;P&gt;You can put the note 'No Records Found' either in one of your char variables,&lt;/P&gt;
&lt;P&gt;assuming it is long enough, or in a new variable which will be absent on the other datasets,&lt;/P&gt;
&lt;P&gt;unless you add it to all datasets with any message in it or empty:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cccc;
&amp;nbsp;set cccc nobs = m;
&amp;nbsp; &amp;nbsp; &amp;nbsp; if m=0 then note='No Records Found'&amp;nbsp;;
&amp;nbsp; &amp;nbsp; &amp;nbsp; else note = cat('Dataset has ',m, ' records');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can add counters to your code to to it in same step&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WWWW TTTT DDDD CCCC;
 set have end=eof;
     length note $20;
     retain n1 n2 n3 n4 0  retain note '  ';
     if Group = 'WWWW' then do; n1+1; output WWWW; end; else
     if Group = 'TTTT' then do; n2+1; output TTTT; end; else
     if Group = 'DDDD' then do; n3+1; output DDDD; end; else
     if Group = 'CCCC' then do; n4+1; output CCCC; end;      
     
     array nx n1-n4;
     array dx $ 'WWWW' 'TTTT' 'DDDD' 'CCCC';
     if eof then &lt;BR /&gt;        do i=1 to dim(nx);
          if nx(i) = 0 then do;
             group = dx(i);
             note = 'No Records Found'; 
            output;
        end;
      end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Nov 2018 16:04:46 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2018-11-07T16:04:46Z</dc:date>
    <item>
      <title>Missing Values Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-Values-Statement/m-p/511039#M137523</link>
      <description>&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;length&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Group $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;50&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Group $ _NAME_ $ Value date $;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WWWW AARP 50 1jun2018&lt;/P&gt;
&lt;P&gt;TTTT BBRP 123 5may2015&lt;/P&gt;
&lt;P&gt;DDDD BBRP 123 5may2015&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; WWWW TTTT DDDD CCCC;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Group = 'WWWW' &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; WWWW;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Group = 'TTTT' &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; TTTT;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Group = 'DDDD' &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; DDDD;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Group = 'CCCC' &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; CCCC;/*has no records*/&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;CCCC will have no records however I want to show the dataset and place a statement under the variable Group and say 'No Records Found'.&amp;nbsp; Can this be done at the dataset level???&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Nov 2018 14:42:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-Values-Statement/m-p/511039#M137523</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2018-11-07T14:42:02Z</dc:date>
    </item>
    <item>
      <title>Re: Missing Values Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-Values-Statement/m-p/511042#M137524</link>
      <description>&lt;P&gt;SAS already does that in the LOG.&lt;/P&gt;
&lt;PRE&gt;NOTE: There were 3 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WWWW has 1 observations and 4 variables.
NOTE: The data set WORK.TTTT has 1 observations and 4 variables.
NOTE: The data set WORK.DDDD has 1 observations and 4 variables.
NOTE: The data set WORK.CCCC has 0 observations and 4 variables.&lt;/PRE&gt;
&lt;P&gt;What are you actually trying to do?&lt;/P&gt;</description>
      <pubDate>Wed, 07 Nov 2018 14:48:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-Values-Statement/m-p/511042#M137524</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-07T14:48:04Z</dc:date>
    </item>
    <item>
      <title>Re: Missing Values Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-Values-Statement/m-p/511043#M137525</link>
      <description>&lt;P&gt;In other words for dataset CCCC I would get the dataset with nothing in it.&amp;nbsp; I want to not only show the dataset CCCC, I want a statement inside the dataset that has the message 'No Records Found'.&amp;nbsp; I eventually want this to be a single report with 4 tabs.&amp;nbsp; If no records appear I want the dataset to list the no record statement&lt;/P&gt;</description>
      <pubDate>Wed, 07 Nov 2018 14:52:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-Values-Statement/m-p/511043#M137525</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2018-11-07T14:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: Missing Values Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-Values-Statement/m-p/511067#M137527</link>
      <description>&lt;P&gt;You can put the note 'No Records Found' either in one of your char variables,&lt;/P&gt;
&lt;P&gt;assuming it is long enough, or in a new variable which will be absent on the other datasets,&lt;/P&gt;
&lt;P&gt;unless you add it to all datasets with any message in it or empty:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cccc;
&amp;nbsp;set cccc nobs = m;
&amp;nbsp; &amp;nbsp; &amp;nbsp; if m=0 then note='No Records Found'&amp;nbsp;;
&amp;nbsp; &amp;nbsp; &amp;nbsp; else note = cat('Dataset has ',m, ' records');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can add counters to your code to to it in same step&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WWWW TTTT DDDD CCCC;
 set have end=eof;
     length note $20;
     retain n1 n2 n3 n4 0  retain note '  ';
     if Group = 'WWWW' then do; n1+1; output WWWW; end; else
     if Group = 'TTTT' then do; n2+1; output TTTT; end; else
     if Group = 'DDDD' then do; n3+1; output DDDD; end; else
     if Group = 'CCCC' then do; n4+1; output CCCC; end;      
     
     array nx n1-n4;
     array dx $ 'WWWW' 'TTTT' 'DDDD' 'CCCC';
     if eof then &lt;BR /&gt;        do i=1 to dim(nx);
          if nx(i) = 0 then do;
             group = dx(i);
             note = 'No Records Found'; 
            output;
        end;
      end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Nov 2018 16:04:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-Values-Statement/m-p/511067#M137527</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-11-07T16:04:46Z</dc:date>
    </item>
    <item>
      <title>Re: Missing Values Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-Values-Statement/m-p/511076#M137530</link>
      <description>Two things to note:&lt;BR /&gt;1 splitting data is almost always a bad idea, because more code is required to process the datasets. Search for by-group-processing.&lt;BR /&gt;2 a "no records found" statement does not exist. The emptiness of a dataset should be enough. You could add a label to the dataset, but that would require post-processing the dataset.</description>
      <pubDate>Wed, 07 Nov 2018 16:31:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-Values-Statement/m-p/511076#M137530</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2018-11-07T16:31:56Z</dc:date>
    </item>
    <item>
      <title>Re: Missing Values Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-Values-Statement/m-p/511085#M137531</link>
      <description>&lt;P&gt;Start out with a single character variable (_NOT_FOUND_LIST) containing a space-separated list of possible group values.&amp;nbsp; As each group is encountered take it out of the variable.&amp;nbsp; At the end of the data set write a dummy record for each group value remaining in _not_found_list:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length Group $50;
input Group $ _NAME_ $ Value date $;
datalines;
WWWW AARP 50 1jun2018
TTTT BBRP 123 5may2015
DDDD BBRP 123 5may2015
run; 

data WWWW TTTT DDDD CCCC;
  set have end=end_of_have;
  retain _not_found_list 'WWWW TTTT DDDD CCCC';
  select (group);
    when ('WWWW') output WWWW;
    when ('TTTT') output TTTT;
    when ('DDDD') output DDDD;
    when ('CCCC') output CCCC;  /*has no records*/
  end;
  _not_found_list=tranwrd(_not_found_list,trim(group),'');
  if end_of_have;
  call missing(group,_name_,value,date);
  group='Not found';
  do while (not missing(_not_found_list));
    select (scan(_not_found_list,1));
      when ('WWWW') output WWWW;
      when ('TTTT') output TTTT;
      when ('DDDD') output DDDD;
      when ('CCCC') output CCCC;
    end;
    _not_found_list=tranwrd(_not_found_list,scan(_not_found_list,1),'');
  end;
  drop _not_found_list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One can make it more compact by reducing the number of loops to one, but more carefully managing the loop conditions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data WWWW TTTT DDDD CCCC;
  set have end=end_of_have;
  retain _not_found_list 'WWWW TTTT DDDD CCCC';

  if _not_found_list^=' ' then _not_found_list=tranwrd(_not_found_list,trim(group),'');
  do _n_=1 to 6 until (end_of_have=0  or _not_found_list=' ');
    select (ifc(_n_=1,group,scan(_not_found_list,1)));
      when ('WWWW') output WWWW;
      when ('TTTT') output TTTT;
      when ('DDDD') output DDDD;
      when ('CCCC') output CCCC;  /*has no records*/
    end;
    if _n_=1 then call missing(_name_,value,date);
    if _n_=1 then group='Not Found';
    else _not_found_list=tranwrd(_not_found_list,scan(_not_found_list,1),' ');
  end;
  drop _not_found_list;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW the "do _n_=1 to&amp;nbsp;6 until ..."&amp;nbsp; could also be "do _n_=1 by 1 until ...", but the latter risks endless loop unless you know the UNTIL condition will always eventually be met.&amp;nbsp; So I put "1 to 6", just making sure&amp;nbsp;to choose an upper limit greater than the number of expected groups (4)&lt;/P&gt;</description>
      <pubDate>Wed, 07 Nov 2018 16:45:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-Values-Statement/m-p/511085#M137531</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-11-07T16:45:37Z</dc:date>
    </item>
  </channel>
</rss>

