<?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 a variable from different dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-different-dates/m-p/263699#M269242</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/81036"&gt;@hwangnyc&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi folks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the response. The date is in SAS DATE9. Format. I left out a column of data that indicates an action complete. Therefore, it's okay to have mutiple IDs and dates because they can be filtered by the variable I left out.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was thinking, It may be easier to create a Baseline/Last&amp;nbsp;Follow up variable first. So the variable would be&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Earliest date = Baseline&lt;/P&gt;
&lt;P&gt;Latest date = Last Follow up&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps a method using the First. Last. method?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Note that the example code uses First but only on ID. For first. logic to work you need something else with each record to idendify the group. Possibly that would be in the other variables you didn't include (and likely should now to see if this approach is feasible.)&lt;/P&gt;</description>
    <pubDate>Wed, 13 Apr 2016 23:22:28 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-04-13T23:22:28Z</dc:date>
    <item>
      <title>Creating a variable from different dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-different-dates/m-p/263627#M269238</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to create a new variable called “Appointment” which will consist 5 categories – Baseline, 3 Month, 6 Month, 9 Month, and 12 Month.&lt;/P&gt;&lt;P&gt;Some sample data looks like&amp;nbsp;&amp;nbsp;looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID EventDate&lt;BR /&gt;2 17NOV2008&lt;BR /&gt;2 23SEP2009&lt;BR /&gt;2 17NOV2008&lt;BR /&gt;2 23SEP2009&lt;BR /&gt;2 17NOV2008&lt;BR /&gt;2 17NOV2008&lt;BR /&gt;3 22DEC2008&lt;BR /&gt;3 24JAN2008&lt;BR /&gt;3 19FEB2008&lt;BR /&gt;3 24JAN2008&lt;BR /&gt;4 24JAN2008&lt;BR /&gt;4 10APR2008&lt;BR /&gt;4 08JUL2008&lt;BR /&gt;4 22DEC2008&lt;BR /&gt;4 01JUL2009&lt;BR /&gt;4 10MAR2010&lt;BR /&gt;4 10DEC2010&lt;BR /&gt;4 24JAN2008&lt;BR /&gt;4 10APR2008&lt;BR /&gt;4 22DEC2008&lt;BR /&gt;4 24JAN2008&lt;BR /&gt;5 27FEB2008&lt;BR /&gt;5 18MAR2008&lt;BR /&gt;5 03SEP2008&lt;BR /&gt;5 22DEC2008&lt;BR /&gt;5 16JUN2009&lt;BR /&gt;5 22MAR2010&lt;BR /&gt;5 27FEB2008&lt;BR /&gt;5 18MAR2008&lt;BR /&gt;5 27FEB2008&lt;BR /&gt;&lt;BR /&gt;What I need is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Baseline = Earliest “EventDate” per “ID”&lt;/P&gt;&lt;P&gt;3 Month = “EventDate” between 31 and 59 days &amp;nbsp;&lt;/P&gt;&lt;P&gt;6 Month = “EventDate” between 60 and 179 days&lt;/P&gt;&lt;P&gt;9 Month = “EventDate” between 180 and 269 days&lt;/P&gt;&lt;P&gt;12 Month = “EventDate” between 270 and 365 days&lt;/P&gt;&lt;P&gt;My challenge is that everyone has a different baseline date. Any suggestions as to how to work around this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2016 18:16:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-different-dates/m-p/263627#M269238</guid>
      <dc:creator>hwangnyc</dc:creator>
      <dc:date>2016-04-13T18:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable from different dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-different-dates/m-p/263636#M269239</link>
      <description>&lt;P&gt;Are your dates character strings, or are they already SAS dates?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How would you like to handle it if a patient has 5 visits that all fall within the 6-month window?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2016 19:18:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-different-dates/m-p/263636#M269239</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-04-13T19:18:10Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable from different dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-different-dates/m-p/263691#M269240</link>
      <description>&lt;P&gt;What about the multiples of the same date? For instance Id 2 has 4 eventdates of 17NOV2008.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I thought this might be a start point but the duplications may not work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   informat id $5. Eventdate date9.;
   Format EventDate date9.;
   input ID EventDate;
datalines;
2 17NOV2008
2 23SEP2009
2 17NOV2008
2 23SEP2009
2 17NOV2008
2 17NOV2008
3 22DEC2008
3 24JAN2008
3 19FEB2008
3 24JAN2008
4 24JAN2008
4 10APR2008
4 08JUL2008
4 22DEC2008
4 01JUL2009
4 10MAR2010
4 10DEC2010
4 24JAN2008
4 10APR2008
4 22DEC2008
4 24JAN2008
5 27FEB2008
5 18MAR2008
5 03SEP2008
5 22DEC2008
5 16JUN2009
5 22MAR2010
5 27FEB2008
5 18MAR2008
5 27FEB2008
run;

/* next bit assumes data is sorted by id eventdate*/
proc sort data = have; by id eventdate;run;

data want;
   set have;
   by id eventdate;
   retain basedate;
   if first.id then basedate=eventdate;
   DaysSinceBase = EventDate - BaseDate;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Apr 2016 21:50:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-different-dates/m-p/263691#M269240</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-13T21:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable from different dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-different-dates/m-p/263693#M269241</link>
      <description>&lt;P&gt;Hi folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the response. The date is in SAS DATE9. Format. I left out a column of data that indicates an action complete. Therefore, it's okay to have mutiple IDs and dates because they can be filtered by the variable I left out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was thinking, It may be easier to create a Baseline/Last&amp;nbsp;Follow up variable first. So the variable would be&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Earliest date = Baseline&lt;/P&gt;&lt;P&gt;Latest date = Last Follow up&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Perhaps a method using the First. Last. method?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2016 22:34:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-different-dates/m-p/263693#M269241</guid>
      <dc:creator>hwangnyc</dc:creator>
      <dc:date>2016-04-13T22:34:40Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable from different dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-different-dates/m-p/263699#M269242</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/81036"&gt;@hwangnyc&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi folks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the response. The date is in SAS DATE9. Format. I left out a column of data that indicates an action complete. Therefore, it's okay to have mutiple IDs and dates because they can be filtered by the variable I left out.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was thinking, It may be easier to create a Baseline/Last&amp;nbsp;Follow up variable first. So the variable would be&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Earliest date = Baseline&lt;/P&gt;
&lt;P&gt;Latest date = Last Follow up&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps a method using the First. Last. method?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Note that the example code uses First but only on ID. For first. logic to work you need something else with each record to idendify the group. Possibly that would be in the other variables you didn't include (and likely should now to see if this approach is feasible.)&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2016 23:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-different-dates/m-p/263699#M269242</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-13T23:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable from different dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-different-dates/m-p/263734#M269243</link>
      <description>&lt;P&gt;Given that EventDate is a SAS date, you ought to be able to code along these lines:&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 id EventDate;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by id EventDate;&lt;/P&gt;
&lt;P&gt;if first.id then baseline_date = EventDate;&lt;/P&gt;
&lt;P&gt;retain baseline_date;&lt;/P&gt;
&lt;P&gt;days_since = EventDate - baseline_date;&lt;/P&gt;
&lt;P&gt;**** Use Days_Since to create the variable you want;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It should be straightforward to create your new variable based on Days_Since at that point.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2016 02:43:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-different-dates/m-p/263734#M269243</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-04-14T02:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable from different dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-different-dates/m-p/263870#M269244</link>
      <description>&lt;P&gt;Astounding - your code worked like a chart. I'm having some difficulties createing the final date. I used the last, statement below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data Events2;&lt;BR /&gt;set Events;&lt;BR /&gt;by childid AsthmaEventDate;&lt;BR /&gt;if first.childid then BaselineEventDate = AsthmaEventDate;&lt;BR /&gt;&lt;STRONG&gt;if last.childid then FinalEventDate = AsthmaEventDate;&lt;/STRONG&gt;&lt;BR /&gt;retain&lt;BR /&gt;BaselineEventDate&lt;BR /&gt;&lt;STRONG&gt;FinalEventDate;&lt;/STRONG&gt;&lt;BR /&gt;format&lt;BR /&gt;BaselineEventDate date9.&lt;BR /&gt;FinalEventDate date9.&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The final event date variable ends up wrong for example 1 case has the FinalEventDate as 22APR2008 when it's really 30JUL2015. Could this be a sorting issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2016 13:38:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-different-dates/m-p/263870#M269244</guid>
      <dc:creator>hwangnyc</dc:creator>
      <dc:date>2016-04-14T13:38:35Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable from different dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-different-dates/m-p/263913#M269245</link>
      <description>&lt;P&gt;I don't see either of those dates in your sample data.&amp;nbsp; We'll have to agree on which data we're using here if we are to compare results.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2016 16:05:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-different-dates/m-p/263913#M269245</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-04-14T16:05:57Z</dc:date>
    </item>
  </channel>
</rss>

