<?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: fill empty cells between non missing cells in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/fill-empty-cells-between-non-missing-cells/m-p/374303#M276286</link>
    <description>&lt;P&gt;What does your data really look like? Surely you don't have variables like 0, 1, 2, etc. since, unless you're using validvarname=any, SAS variables can't start with a number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 09 Jul 2017 18:20:31 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-07-09T18:20:31Z</dc:date>
    <item>
      <title>fill empty cells between non missing cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fill-empty-cells-between-non-missing-cells/m-p/374296#M276285</link>
      <description>&lt;P&gt;Hi -&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to fill the missing data between non missing data, the variales are hours, people can work during day time or night time:&lt;/P&gt;&lt;P&gt;id &amp;nbsp; 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;Now I know the start and stop hour for each id, for instance, id1 started at 8am and stopped at 5pm, id2 started at 1pm and stopped&amp;nbsp;&lt;/P&gt;&lt;P&gt;at 9pm. id3 worked at night so he/she started at 11pm and stopped next morning at 6am. &amp;nbsp;I want to fill the hours between their start&lt;/P&gt;&lt;P&gt;and stop hours so that the output can look like this (the time when people were not at work should be left as missing):&lt;/P&gt;&lt;P&gt;id &amp;nbsp; 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 1 1 &amp;nbsp; 1 &amp;nbsp; 1 &amp;nbsp; 1 &amp;nbsp; 1 &amp;nbsp; 1 &amp;nbsp; &amp;nbsp;1 &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; 1 &amp;nbsp; 1 &amp;nbsp; 1 &amp;nbsp; 1 &amp;nbsp;1 &amp;nbsp; &amp;nbsp;1 &amp;nbsp; 1 &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp;1 1 1 1 1 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;Any idea about how to do that? I think the tricky part is for people who&amp;nbsp;were on&amp;nbsp;nightshift (crossed midnight).&lt;/P&gt;&lt;P&gt;Thanks!!!&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jul 2017 17:52:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fill-empty-cells-between-non-missing-cells/m-p/374296#M276285</guid>
      <dc:creator>panda</dc:creator>
      <dc:date>2017-07-09T17:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: fill empty cells between non missing cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fill-empty-cells-between-non-missing-cells/m-p/374303#M276286</link>
      <description>&lt;P&gt;What does your data really look like? Surely you don't have variables like 0, 1, 2, etc. since, unless you're using validvarname=any, SAS variables can't start with a number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jul 2017 18:20:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fill-empty-cells-between-non-missing-cells/m-p/374303#M276286</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-09T18:20:31Z</dc:date>
    </item>
    <item>
      <title>Re: fill empty cells between non missing cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fill-empty-cells-between-non-missing-cells/m-p/374304#M276287</link>
      <description>&lt;P&gt;Sorry, the variables are like time0 time1 time2 ... time23.&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jul 2017 18:21:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fill-empty-cells-between-non-missing-cells/m-p/374304#M276287</guid>
      <dc:creator>panda</dc:creator>
      <dc:date>2017-07-09T18:21:36Z</dc:date>
    </item>
    <item>
      <title>Re: fill empty cells between non missing cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fill-empty-cells-between-non-missing-cells/m-p/374307#M276288</link>
      <description>&lt;P&gt;Here is one way:&lt;/P&gt;
&lt;PRE&gt;data have;
  input id time0-time23;
  cards;
1 . . . . . . . . 1 . . . . . . . . 1 . . . . . .                 
2 . . . . . . . . . . . . . 1 . . . . . . . 1 . .
3 . . . . . . 1 . . . . . . . . . . . . . . . . 1
4 . . . . . . 1 . . . . . . . . . . . . . . . 1 .
5 1 . . . . . . . . . . . . . . . . . . . . . . 1
;

data want (drop=x y i);
  set have;
  array times(0:23) time0-time23;
  x=whichn(1,of times(*))-1;
  y=24-whichn(1,of time23-time0);
  if y-x le 12 then do i=x+1 to y;
    times(i)=1;
  end;
  else do;
    do i=y to 23;
      times(i)=1;
    end;
    do i=0 to x;
      times(i)=1;
    end;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jul 2017 19:03:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fill-empty-cells-between-non-missing-cells/m-p/374307#M276288</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-09T19:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: fill empty cells between non missing cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fill-empty-cells-between-non-missing-cells/m-p/374308#M276289</link>
      <description>&lt;P&gt;Thanks!!!&lt;/P&gt;&lt;P&gt;I am not familiar with the whichn function, cannot find sas profile on this function.&amp;nbsp;Could you explain briefly what does it do or do you&lt;/P&gt;&lt;P&gt;have any links about it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jul 2017 19:14:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fill-empty-cells-between-non-missing-cells/m-p/374308#M276289</guid>
      <dc:creator>panda</dc:creator>
      <dc:date>2017-07-09T19:14:42Z</dc:date>
    </item>
    <item>
      <title>Re: fill empty cells between non missing cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fill-empty-cells-between-non-missing-cells/m-p/374310#M276290</link>
      <description>&lt;P&gt;Here is a link to the documentation:&amp;nbsp;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a003122573.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a003122573.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you enter the variable list backwards (like time23-time0) is searches backwards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jul 2017 19:24:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fill-empty-cells-between-non-missing-cells/m-p/374310#M276290</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-09T19:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: fill empty cells between non missing cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fill-empty-cells-between-non-missing-cells/m-p/374312#M276291</link>
      <description>&lt;P&gt;Better yet, here is a link to the current documentation:&amp;nbsp;&lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/viewer.htm#p0zs0pv38mel2jn1in4lte2akx4d.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/viewer.htm#p0zs0pv38mel2jn1in4lte2akx4d.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you save that link, you'll likely find it useful as the left most column lists all of the SAS functions and call routines and has links to their documentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jul 2017 19:28:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fill-empty-cells-between-non-missing-cells/m-p/374312#M276291</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-09T19:28:11Z</dc:date>
    </item>
    <item>
      <title>Re: fill empty cells between non missing cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fill-empty-cells-between-non-missing-cells/m-p/374313#M276292</link>
      <description>&lt;P&gt;Sorry I forgot another scenario of the problem, if the data is like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id time0-time23;
  cards;
1 . . . . 1 . . . 1 . . . . . 1 . . . 1 . . . . .                 
2 . 1 . . 1 . . . . . . . . 1 . . . . . . . 1 . .
3 . . . . . . 1 . . 1 . . . . . . . . 1 . . . . 1
4 . . 1 . . . 1 . . . . . . . . . 1 . . . . . 1 .
5 . . . . 1 . . . . . . . . . . . . . . 1 . . . . 
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In this case, each person has multiple start and stop hours, like for id 1, he/she started at 4am and stopped at 8am, then started again&lt;/P&gt;&lt;P&gt;at 2pm and stopped at 6pm, want to fill the gap between each start and stop times but leave missing cells as missing between them:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1 . . . . 1 1 1 1 1 . . . . . 1 1 1 1 1 . . . . .                 
2 . 1 1 1 1 . . . . . . . . 1 1 1 1 1 1 1 1 1 . .
3 . . . . . . 1 1 1 1 . . . . . . . . 1 1 1 1 1 1
4 1 1 1 . . . 1 1 1 1 1 1 1 1 1 1 1 . . . . . 1 1
5 1 1 1 1 1 . . . . . . . . . . . . . . 1 1 1 1 1 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Thanks!!!&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jul 2017 19:53:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fill-empty-cells-between-non-missing-cells/m-p/374313#M276292</guid>
      <dc:creator>panda</dc:creator>
      <dc:date>2017-07-09T19:53:09Z</dc:date>
    </item>
    <item>
      <title>Re: fill empty cells between non missing cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fill-empty-cells-between-non-missing-cells/m-p/374350#M276293</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/151080"&gt;@panda&lt;/a&gt;: I'm too tired to think of a fancy way to to that so here is a brute force method. The only scenario it can't account for is a series of multiple shifts combined with an overnight shift:&lt;/P&gt;
&lt;PRE&gt;data have;
  input id time0-time23;
  cards;
0 1 1 . . . . . . 1 . 1 . . . . . . . 1 1 . 1 . 1                 
1 . . . . 1 . . . 1 . . . . . 1 . . . 1 . . . . .                 
2 . 1 . . 1 . . . . . . . . 1 . . . . . . . 1 . .
3 . . . . . . 1 . . 1 . . . . . . . . 1 . . . . 1
4 . . 1 . . . 1 . . . . . . . . . 1 . . . . . 1 .
5 . . . . 1 . . . . . . . . . . . . . . 1 . . . . 
;

data want (drop=x y i /*counter*/);
  set have;
  array times(0:23) time0-time23;
  length times_string $24;
  times_string='';
  counter=0;
  do i=0 to 23;
    if times(i) eq 1 then do;
      counter+1;
      times_string=catt(times_string,mod(counter,2));
    end;
    else times_string=catt(times_string,'.');
  end;
  if counter eq 2 then do;
    x=whichn(1,of times(*))-1;
    y=24-whichn(1,of time23-time0);
    if y-x le 12 then do i=x+1 to y;
      times(i)=1;
    end;
    else do;
      do i=y to 23;
        times(i)=1;
      end;
      do i=0 to x;
        times(i)=1;
      end;
    end;
  end;
  else if counter gt 2 then do;
    do x=0 to 22;
      if times(x) eq 1 then do y=x+1 to 23;
        if times(y) eq 1 then do;
          x=y;
          leave;
        end;
        else times(y)=1;
      end;
    end;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 02:38:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fill-empty-cells-between-non-missing-cells/m-p/374350#M276293</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-10T02:38:50Z</dc:date>
    </item>
    <item>
      <title>Re: fill empty cells between non missing cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fill-empty-cells-between-non-missing-cells/m-p/374484#M276294</link>
      <description>&lt;P&gt;Thanks so much, this is very helpful!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 13:04:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fill-empty-cells-between-non-missing-cells/m-p/374484#M276294</guid>
      <dc:creator>panda</dc:creator>
      <dc:date>2017-07-10T13:04:11Z</dc:date>
    </item>
  </channel>
</rss>

