<?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: Add line with missing period - SAS EG in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Add-line-with-missing-period-SAS-EG/m-p/433984#M68841</link>
    <description>&lt;P&gt;For this (or any) approach to work, your BEGDA values must be actual SAS dates, not character strings.&amp;nbsp; So you will need to learn how SAS handles dates, if you don't already know.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Under that assumption, here's a way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by name begda;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by name;&lt;/P&gt;
&lt;P&gt;prior_end = lag(endda);&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;if first.name=0 and (begda &amp;gt; prior_end + 1) then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;endda = begda - 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;begda = prior_end + 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;ill='N';&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop prior_end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then optionally:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=want;&lt;/P&gt;
&lt;P&gt;by name begda;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Sun, 04 Feb 2018 17:48:38 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-02-04T17:48:38Z</dc:date>
    <item>
      <title>Add line with missing period - SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-line-with-missing-period-SAS-EG/m-p/433983#M68840</link>
      <description>Hey&lt;BR /&gt;I’m a bit struggeling with this one. I have a list in sas that shows periods of illness. It is sorted by name and startdate (BEGDA)&lt;BR /&gt;&lt;BR /&gt;NAME BEGDA ENDDA ILL&lt;BR /&gt;Jones 2/11/2015 2/16/2015 Y&lt;BR /&gt;Jones 3/7/2015 3/12/2015 Y&lt;BR /&gt;Fields 11/5/2017 12/23/2017 Y&lt;BR /&gt;Fields 1/1/2018 1/14/2018 Y&lt;BR /&gt;Smith 3/12/2014 5/12/2014 Y&lt;BR /&gt;Smith 5/15/2014 5/17/2014 Y&lt;BR /&gt;Smith 7/20/2016 7/27/2016 Y&lt;BR /&gt;.... .... ....&lt;BR /&gt;I need to find a way to add a line per individual with the missing period(=the period between two illnesses). For Jones this should be the output:&lt;BR /&gt;&lt;BR /&gt;NAME BEGDA ENDDA ILL&lt;BR /&gt;Jones 2/11/2015 2/16/2015 Y&lt;BR /&gt;Jones 2/17/2015 3/6/2015 N&lt;BR /&gt;Jones 3/7/2015 3/12/2015 Y&lt;BR /&gt;&lt;BR /&gt;Is there a way to code this into a program or something like that. I’m new in sas so any help would be welcome.&lt;BR /&gt;Thanks!</description>
      <pubDate>Sun, 04 Feb 2018 17:20:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-line-with-missing-period-SAS-EG/m-p/433983#M68840</guid>
      <dc:creator>Davoz7</dc:creator>
      <dc:date>2018-02-04T17:20:30Z</dc:date>
    </item>
    <item>
      <title>Re: Add line with missing period - SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-line-with-missing-period-SAS-EG/m-p/433984#M68841</link>
      <description>&lt;P&gt;For this (or any) approach to work, your BEGDA values must be actual SAS dates, not character strings.&amp;nbsp; So you will need to learn how SAS handles dates, if you don't already know.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Under that assumption, here's a way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by name begda;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by name;&lt;/P&gt;
&lt;P&gt;prior_end = lag(endda);&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;if first.name=0 and (begda &amp;gt; prior_end + 1) then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;endda = begda - 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;begda = prior_end + 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;ill='N';&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop prior_end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then optionally:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=want;&lt;/P&gt;
&lt;P&gt;by name begda;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2018 17:48:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-line-with-missing-period-SAS-EG/m-p/433984#M68841</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-04T17:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: Add line with missing period - SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-line-with-missing-period-SAS-EG/m-p/433985#M68842</link>
      <description>&lt;P&gt;Use the lag() function to access previous records.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=want;
by name;
run;

data want;
set have;
by name;
prevend = lag(endda);
output;
if not first.name and prevend &amp;lt; begda
then do;
  ill = 'N';
  endda = begda - 1;
  begda = prevend;
  output;
end;
drop prevend;
run;

proc sort data=want;
by name begda;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Feb 2018 17:54:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-line-with-missing-period-SAS-EG/m-p/433985#M68842</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-02-04T17:54:59Z</dc:date>
    </item>
    <item>
      <title>Re: Add line with missing period - SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-line-with-missing-period-SAS-EG/m-p/434009#M68845</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input NAME $ (BEGDA ENDDA) (:mmddyy10.) ILL $;
format BEGDA ENDDA mmddyy10.;
datalines;
Jones 2/11/2015 2/16/2015 Y
Jones 3/7/2015 3/12/2015 Y
Fields 11/5/2017 12/23/2017 Y
Fields 1/1/2018 1/14/2018 Y
Smith 3/12/2014 5/12/2014 Y
Smith 5/15/2014 5/17/2014 Y
Smith 7/20/2016 7/27/2016 Y
;

data want;
set have;
by name notsorted;
retain _date;
if first.name then do; _date=ENDDA;output;end;
else if _date ne BEGDA-1 then do; 
_BEGDA=BEGDA;_ENDDA=ENDDA;_ll=ill;
BEGDA=_date+1; ENDDA=_BEGDA-1;ill='N';
output;
BEGDA=_BEGDA;
ENDDA=_ENDDA;
ill=_ll;
output;
_date=ENDDA;
end;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Feb 2018 20:42:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-line-with-missing-period-SAS-EG/m-p/434009#M68845</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-02-04T20:42:43Z</dc:date>
    </item>
  </channel>
</rss>

