<?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: Creating New Records using Retain and If Statements in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Creating-New-Records-using-Retain-and-If-Statements/m-p/70942#M20456</link>
    <description>This is known as interpolation. If you have SAS/ETS licensed, look at PROC EXPAND.&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; Hello, &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I was wondering if you may be able to help me. &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I'm trying to create new records between existing.&lt;BR /&gt;
&amp;gt; What I've got is records with an Id, a Value, start&lt;BR /&gt;
&amp;gt; date and and end date, so for example 001, $5000,&lt;BR /&gt;
&amp;gt; 01JUN2009 to 21OCT2009. Then the next is 001, $4700,&lt;BR /&gt;
&amp;gt; 22OCT2009 to 15DEC2009. &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; What I'd like to do is create a new record counted by&lt;BR /&gt;
&amp;gt; month in between the start and end date and then also&lt;BR /&gt;
&amp;gt; assign a new value in between, so something like...&lt;BR /&gt;
&amp;gt;  &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; 001, $5000, 01JUN2009, 01JUL2009.&lt;BR /&gt;
&amp;gt; 001, $4900, 01JUL2009 to 01AUG2009.&lt;BR /&gt;
&amp;gt; 001, $4800, 01AUG2009 to 01SEP2009.&lt;BR /&gt;
&amp;gt; 001, $4700, 01SEP2009 to 01OCT2009.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; What I've been exploring is something along the lines&lt;BR /&gt;
&amp;gt; of... &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Proc Sort data=Sample;&lt;BR /&gt;
&amp;gt; by id startdate;&lt;BR /&gt;
&amp;gt; run;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Data Gaps;&lt;BR /&gt;
&amp;gt; Set Sample;&lt;BR /&gt;
&amp;gt; By Id startdate;&lt;BR /&gt;
&amp;gt; Retain Startdate Enddate Value;&lt;BR /&gt;
&amp;gt; If First.Id then output;&lt;BR /&gt;
&amp;gt; else do; &lt;BR /&gt;
&amp;gt; Month_Gap = INTCK( 'month', Startdate, Enddate);&lt;BR /&gt;
&amp;gt; if Month_Gap = 0 then do;&lt;BR /&gt;
&amp;gt; StartDate1= intnx('month',Startdate,0,'beginning');&lt;BR /&gt;
&amp;gt; EndDate1 = intnx('month',Enddate,1,'beginning');&lt;BR /&gt;
&amp;gt; output;&lt;BR /&gt;
&amp;gt; end;&lt;BR /&gt;
&amp;gt; .........&lt;BR /&gt;
&amp;gt; ..........&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I know what that produces and it's certainly not the&lt;BR /&gt;
&amp;gt; desired result but that's what I've been playing&lt;BR /&gt;
&amp;gt; around with trying to work it out.</description>
    <pubDate>Mon, 30 May 2011 13:24:21 GMT</pubDate>
    <dc:creator>Howles</dc:creator>
    <dc:date>2011-05-30T13:24:21Z</dc:date>
    <item>
      <title>Creating New Records using Retain and If Statements</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-New-Records-using-Retain-and-If-Statements/m-p/70940#M20454</link>
      <description>Hello, &lt;BR /&gt;
&lt;BR /&gt;
I was wondering if you may be able to help me. &lt;BR /&gt;
&lt;BR /&gt;
I'm trying to create new records between existing. What I've got is records with an Id, a Value, start date and and end date, so for example 001, $5000, 01JUN2009 to 21OCT2009. Then the next is 001, $4700, 22OCT2009 to 15DEC2009. &lt;BR /&gt;
&lt;BR /&gt;
What I'd like to do is create a new record counted by month in between the start and end date and then also assign a new value in between, so something like...  &lt;BR /&gt;
&lt;BR /&gt;
001, $5000, 01JUN2009, 01JUL2009.&lt;BR /&gt;
001, $4900, 01JUL2009 to 01AUG2009.&lt;BR /&gt;
001, $4800, 01AUG2009 to 01SEP2009.&lt;BR /&gt;
001, $4700, 01SEP2009 to 01OCT2009.&lt;BR /&gt;
&lt;BR /&gt;
What I've been exploring is something along the lines of... &lt;BR /&gt;
&lt;BR /&gt;
Proc Sort data=Sample;&lt;BR /&gt;
by id startdate;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Data Gaps;&lt;BR /&gt;
Set Sample;&lt;BR /&gt;
By Id startdate;&lt;BR /&gt;
Retain Startdate Enddate Value;&lt;BR /&gt;
If First.Id then output;&lt;BR /&gt;
else do; &lt;BR /&gt;
Month_Gap = INTCK( 'month', Startdate, Enddate);&lt;BR /&gt;
if Month_Gap = 0 then do;&lt;BR /&gt;
StartDate1= intnx('month',Startdate,0,'beginning');&lt;BR /&gt;
EndDate1 = intnx('month',Enddate,1,'beginning');&lt;BR /&gt;
output;&lt;BR /&gt;
end;&lt;BR /&gt;
.........&lt;BR /&gt;
..........&lt;BR /&gt;
&lt;BR /&gt;
I know what that produces and it's certainly not the desired result but that's what I've been playing around with trying to work it out.</description>
      <pubDate>Mon, 30 May 2011 02:06:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-New-Records-using-Retain-and-If-Statements/m-p/70940#M20454</guid>
      <dc:creator>SamT</dc:creator>
      <dc:date>2011-05-30T02:06:11Z</dc:date>
    </item>
    <item>
      <title>Re: Creating New Records using Retain and If Statements</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-New-Records-using-Retain-and-If-Statements/m-p/70941#M20455</link>
      <description>Sam,&lt;BR /&gt;
&lt;BR /&gt;
The following definitely ISN'T tested code, but it should be close enough to allow you to figure out how to get what you want:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data sample;&lt;BR /&gt;
  input id $3. value dollar8.0 (startdate enddate) (date9. :);&lt;BR /&gt;
  cards;&lt;BR /&gt;
001 $5000. 01JUN2009 1JUL2009.&lt;BR /&gt;
001 $4700. 01SEP2009 01OCT2009.&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=Sample;&lt;BR /&gt;
  by id startdate;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data gaps (keep=id startdate enddate value);&lt;BR /&gt;
  set sample (rename=(&lt;BR /&gt;
    startdate=current_startdate&lt;BR /&gt;
    enddate=current_enddate&lt;BR /&gt;
    value=current_value&lt;BR /&gt;
	))&lt;BR /&gt;
;&lt;BR /&gt;
  by Id;&lt;BR /&gt;
  format startdate enddate date9.;&lt;BR /&gt;
  retain last_startdate last_enddate last_value;&lt;BR /&gt;
  if first.Id then do;&lt;BR /&gt;
    call missing(last_startdate);&lt;BR /&gt;
    call missing(last_enddate);&lt;BR /&gt;
    call missing(last_value);&lt;BR /&gt;
	startdate=current_startdate;&lt;BR /&gt;
    enddate=current_enddate;&lt;BR /&gt;
    value=current_value;&lt;BR /&gt;
    output;&lt;BR /&gt;
  end;&lt;BR /&gt;
  else do;&lt;BR /&gt;
    value_increment=(current_value-last_value)/&lt;BR /&gt;
     (INTCK( 'month', last_enddate,current_startdate)+1);&lt;BR /&gt;
    do i=0 to INTCK( 'month', last_enddate,&lt;BR /&gt;
      current_startdate);&lt;BR /&gt;
      startdate= intnx('month',last_startdate,i+1,'beginning');&lt;BR /&gt;
      enddate = intnx('month',last_enddate,i+1,'beginning');&lt;BR /&gt;
      value=last_value+(i+1)*value_increment;&lt;BR /&gt;
      output;&lt;BR /&gt;
    end;&lt;BR /&gt;
  end;&lt;BR /&gt;
  last_startdate=current_startdate;&lt;BR /&gt;
  last_enddate=current_enddate;&lt;BR /&gt;
  last_value=current_value;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
HTH,&lt;BR /&gt;
Art&lt;BR /&gt;
--------&lt;BR /&gt;
&amp;gt; Hello, &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I was wondering if you may be able to help me. &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I'm trying to create new records between existing.&lt;BR /&gt;
&amp;gt; What I've got is records with an Id, a Value, start&lt;BR /&gt;
&amp;gt; date and and end date, so for example 001, $5000,&lt;BR /&gt;
&amp;gt; 01JUN2009 to 21OCT2009. Then the next is 001, $4700,&lt;BR /&gt;
&amp;gt; 22OCT2009 to 15DEC2009. &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; What I'd like to do is create a new record counted by&lt;BR /&gt;
&amp;gt; month in between the start and end date and then also&lt;BR /&gt;
&amp;gt; assign a new value in between, so something like...&lt;BR /&gt;
&amp;gt;  &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; 001, $5000, 01JUN2009, 01JUL2009.&lt;BR /&gt;
&amp;gt; 001, $4900, 01JUL2009 to 01AUG2009.&lt;BR /&gt;
&amp;gt; 001, $4800, 01AUG2009 to 01SEP2009.&lt;BR /&gt;
&amp;gt; 001, $4700, 01SEP2009 to 01OCT2009.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; What I've been exploring is something along the lines&lt;BR /&gt;
&amp;gt; of... &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Proc Sort data=Sample;&lt;BR /&gt;
&amp;gt; by id startdate;&lt;BR /&gt;
&amp;gt; run;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Data Gaps;&lt;BR /&gt;
&amp;gt; Set Sample;&lt;BR /&gt;
&amp;gt; By Id startdate;&lt;BR /&gt;
&amp;gt; Retain Startdate Enddate Value;&lt;BR /&gt;
&amp;gt; If First.Id then output;&lt;BR /&gt;
&amp;gt; else do; &lt;BR /&gt;
&amp;gt; Month_Gap = INTCK( 'month', Startdate, Enddate);&lt;BR /&gt;
&amp;gt; if Month_Gap = 0 then do;&lt;BR /&gt;
&amp;gt; StartDate1= intnx('month',Startdate,0,'beginning');&lt;BR /&gt;
&amp;gt; EndDate1 = intnx('month',Enddate,1,'beginning');&lt;BR /&gt;
&amp;gt; output;&lt;BR /&gt;
&amp;gt; end;&lt;BR /&gt;
&amp;gt; .........&lt;BR /&gt;
&amp;gt; ..........&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I know what that produces and it's certainly not the&lt;BR /&gt;
&amp;gt; desired result but that's what I've been playing&lt;BR /&gt;
&amp;gt; around with trying to work it out.</description>
      <pubDate>Mon, 30 May 2011 12:56:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-New-Records-using-Retain-and-If-Statements/m-p/70941#M20455</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-05-30T12:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: Creating New Records using Retain and If Statements</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-New-Records-using-Retain-and-If-Statements/m-p/70942#M20456</link>
      <description>This is known as interpolation. If you have SAS/ETS licensed, look at PROC EXPAND.&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; Hello, &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I was wondering if you may be able to help me. &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I'm trying to create new records between existing.&lt;BR /&gt;
&amp;gt; What I've got is records with an Id, a Value, start&lt;BR /&gt;
&amp;gt; date and and end date, so for example 001, $5000,&lt;BR /&gt;
&amp;gt; 01JUN2009 to 21OCT2009. Then the next is 001, $4700,&lt;BR /&gt;
&amp;gt; 22OCT2009 to 15DEC2009. &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; What I'd like to do is create a new record counted by&lt;BR /&gt;
&amp;gt; month in between the start and end date and then also&lt;BR /&gt;
&amp;gt; assign a new value in between, so something like...&lt;BR /&gt;
&amp;gt;  &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; 001, $5000, 01JUN2009, 01JUL2009.&lt;BR /&gt;
&amp;gt; 001, $4900, 01JUL2009 to 01AUG2009.&lt;BR /&gt;
&amp;gt; 001, $4800, 01AUG2009 to 01SEP2009.&lt;BR /&gt;
&amp;gt; 001, $4700, 01SEP2009 to 01OCT2009.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; What I've been exploring is something along the lines&lt;BR /&gt;
&amp;gt; of... &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Proc Sort data=Sample;&lt;BR /&gt;
&amp;gt; by id startdate;&lt;BR /&gt;
&amp;gt; run;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Data Gaps;&lt;BR /&gt;
&amp;gt; Set Sample;&lt;BR /&gt;
&amp;gt; By Id startdate;&lt;BR /&gt;
&amp;gt; Retain Startdate Enddate Value;&lt;BR /&gt;
&amp;gt; If First.Id then output;&lt;BR /&gt;
&amp;gt; else do; &lt;BR /&gt;
&amp;gt; Month_Gap = INTCK( 'month', Startdate, Enddate);&lt;BR /&gt;
&amp;gt; if Month_Gap = 0 then do;&lt;BR /&gt;
&amp;gt; StartDate1= intnx('month',Startdate,0,'beginning');&lt;BR /&gt;
&amp;gt; EndDate1 = intnx('month',Enddate,1,'beginning');&lt;BR /&gt;
&amp;gt; output;&lt;BR /&gt;
&amp;gt; end;&lt;BR /&gt;
&amp;gt; .........&lt;BR /&gt;
&amp;gt; ..........&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I know what that produces and it's certainly not the&lt;BR /&gt;
&amp;gt; desired result but that's what I've been playing&lt;BR /&gt;
&amp;gt; around with trying to work it out.</description>
      <pubDate>Mon, 30 May 2011 13:24:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-New-Records-using-Retain-and-If-Statements/m-p/70942#M20456</guid>
      <dc:creator>Howles</dc:creator>
      <dc:date>2011-05-30T13:24:21Z</dc:date>
    </item>
  </channel>
</rss>

