<?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: Possible to add a row to dataset for missing values? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Possible-to-add-a-row-to-dataset-for-missing-values/m-p/409737#M67223</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lets start with the usual, post test data in the form of a datastep, a picture is useless to us.&amp;nbsp; Also show what output you need.&amp;nbsp; From what you post, I cannot see a row for 09/02/2015, nor any logic why that should be added and not 09/03/2017?&lt;/P&gt;
&lt;P&gt;To answer you final question, yes loops are one method:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  retain lstdt;
  if _n_=1 then lstdt=start_date;
  else do;
    if start_date + 1 ne lstdt then do;
      do i=start_date to lstdt;
        output;
        start_date=start_date+i;
      end;
    end;
    else output;
  end;
run;
  &lt;/PRE&gt;
&lt;P&gt;Something like that.&lt;/P&gt;</description>
    <pubDate>Thu, 02 Nov 2017 09:12:03 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-11-02T09:12:03Z</dc:date>
    <item>
      <title>Possible to add a row to dataset for missing values?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Possible-to-add-a-row-to-dataset-for-missing-values/m-p/409732#M67222</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm stuck on a problem here that I hope there is a solution for somewhere in the SAS-commands.&lt;/P&gt;&lt;P&gt;The data looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Skärmavbild 2017-11-02 kl. 09.26.32.jpg" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16374i37A8E1DEBCEAF7CA/image-size/large?v=v2&amp;amp;px=999" role="button" title="Skärmavbild 2017-11-02 kl. 09.26.32.jpg" alt="Skärmavbild 2017-11-02 kl. 09.26.32.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The raw-data consists of number of cars arriving at a certain location. There is a file when they arrive (this one) and one when they leave. The data of interest is datum (date), timme (hour) and freq ) sum of number of cars arriving during that hour that date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the raw-data there might be some hours certain days when no cars arrive, as you can see above (hour 0, 09/02/2015 for example).&lt;/P&gt;&lt;P&gt;I need to match this file with the other to get the total sum of cars present every hour, taking the sum of arriving cars and subtract the leaving.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Problem is I need to have rows even when there are 0 cars arriving, not a missing row like seen above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any way I can make a loop or something similar to check if there are rows for every hour (0-23), every day (whole 2015). If the row is missing SAS will add the row with the date and hour missing with FREQ=0. Is this possible?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Peter Karlsson&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2017 08:39:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Possible-to-add-a-row-to-dataset-for-missing-values/m-p/409732#M67222</guid>
      <dc:creator>PeterK</dc:creator>
      <dc:date>2017-11-02T08:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: Possible to add a row to dataset for missing values?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Possible-to-add-a-row-to-dataset-for-missing-values/m-p/409737#M67223</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lets start with the usual, post test data in the form of a datastep, a picture is useless to us.&amp;nbsp; Also show what output you need.&amp;nbsp; From what you post, I cannot see a row for 09/02/2015, nor any logic why that should be added and not 09/03/2017?&lt;/P&gt;
&lt;P&gt;To answer you final question, yes loops are one method:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  retain lstdt;
  if _n_=1 then lstdt=start_date;
  else do;
    if start_date + 1 ne lstdt then do;
      do i=start_date to lstdt;
        output;
        start_date=start_date+i;
      end;
    end;
    else output;
  end;
run;
  &lt;/PRE&gt;
&lt;P&gt;Something like that.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2017 09:12:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Possible-to-add-a-row-to-dataset-for-missing-values/m-p/409737#M67223</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-02T09:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: Possible to add a row to dataset for missing values?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Possible-to-add-a-row-to-dataset-for-missing-values/m-p/409812#M67227</link>
      <description>&lt;P&gt;You can make a dummy data set of DATUM and TIMME values for 2015. Then interleave with datasets ARRIVE and LEAVE:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data date_time_dummies;
  do datum='01jan2015'd to '31dec2015'd;
    do timme=0 to 23;
      output;
    end;
  end;
  format datum mmddyy10.;
run;

data want (keep=datum timme total);
  set arrive (in=ina) leave (in=inL) date_time_dummies;
  by datum timme;
  retain total 0;

  if ina then total=total+_freq_;
  else if inL then total=total-_freq_;
  if last.timme;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Nov 2017 13:17:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Possible-to-add-a-row-to-dataset-for-missing-values/m-p/409812#M67227</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-11-02T13:17:14Z</dc:date>
    </item>
    <item>
      <title>Re: Possible to add a row to dataset for missing values?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Possible-to-add-a-row-to-dataset-for-missing-values/m-p/411839#M67364</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm sorry for not getting back to you before. I have been&amp;nbsp;away for some days but now I'm back.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We have decided to go with another solution so this case can be closed &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for the input though!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Peter Karlsson&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2017 08:56:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Possible-to-add-a-row-to-dataset-for-missing-values/m-p/411839#M67364</guid>
      <dc:creator>PeterK</dc:creator>
      <dc:date>2017-11-09T08:56:18Z</dc:date>
    </item>
  </channel>
</rss>

