<?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: Create visit variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-visit-variable/m-p/198400#M305576</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That was much simpler than I thought, thank you both for your input, the code worked.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 08 Jul 2015 16:57:56 GMT</pubDate>
    <dc:creator>rfarmenta</dc:creator>
    <dc:date>2015-07-08T16:57:56Z</dc:date>
    <item>
      <title>Create visit variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-visit-variable/m-p/198397#M305573</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a long dataset that includes multiple records per participant. Each person has an overall date range (begin_date and end_date) for trips they have made to conduct business for their job. Additionally, each person has a date1 and a dot1 that indicated shorter duration trips that fall within their overall begin_date and end_date. What I need is a new variable that gives a trip number for each row of the data. So for example, in the small dataset below for participant 1, row 1 would be trip 1, so my new variable trip, would be equal to 1, rows 2-5 are trip 2 and there were 4 shorter trips associated with trip 2, then rows 6-9 are trip 3 and they were 4 shorter trips associated with the overall date range. You can tell if the date1 and dot1 dates are all within a larger trip if the dates fall within begin_date and end_date. So basically I want to add a variable called trip and for the example row 1 would be 1, rows 2-5 would be 2, and rows 6-9 would be 3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried using the following code but it just gives me a count of all the rows essentially. I think the code doesn't work because I have repeated measures and it is hard to distinguish between dates but I was hoping to be able to do this without transforming the data. Any help would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;trip+1;&lt;/P&gt;&lt;P&gt;by begin_date;&lt;/P&gt;&lt;P&gt;if first.begin_date then trip=1;&lt;/P&gt;&lt;P&gt;else if date1&amp;gt;end_date and dot1&amp;lt;=end_date then trip=trip+1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" jive-data-cell="{&amp;quot;color&amp;quot;:&amp;quot;#000000&amp;quot;,&amp;quot;textAlign&amp;quot;:&amp;quot;left&amp;quot;,&amp;quot;padding&amp;quot;:&amp;quot;2&amp;quot;}" jive-data-header="{&amp;quot;color&amp;quot;:&amp;quot;#FFFFFF&amp;quot;,&amp;quot;backgroundColor&amp;quot;:&amp;quot;#6690BC&amp;quot;,&amp;quot;textAlign&amp;quot;:&amp;quot;center&amp;quot;,&amp;quot;padding&amp;quot;:&amp;quot;2&amp;quot;,&amp;quot;fontFamily&amp;quot;:&amp;quot;arial,helvetica,sans-serif&amp;quot;}" style="border: 1px solid #000000; width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;ID&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;begin_date&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;end_date&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;date1&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;dot1&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;02/12/06&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;04/29/06&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;02/12/06&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;04/29/16&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;03/14/07&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;01/15/08&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;03/14/07&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;04/18/07&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;03/14/07&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;P&gt;01/15/08&lt;/P&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;04/18/07&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;05/16/07&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;03/14/07&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;P&gt;01/15/08&lt;/P&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;05/16/07&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;09/02/07&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;03/14/07&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;P&gt;01/15/08&lt;/P&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;09/02/07&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;01//15/08&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;05/15/10&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;08/05/12&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;06/26/10&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;08/15/10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;05/15/10&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;08/05/12&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;01/20/11&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;01/25/11&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;05/15/10&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;08/05/12&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;02/01/11&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;08/01/11&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;05/15/10&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;08/05/12&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;04/01/12&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;04/03/12&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jul 2015 15:27:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-visit-variable/m-p/198397#M305573</guid>
      <dc:creator>rfarmenta</dc:creator>
      <dc:date>2015-07-08T15:27:18Z</dc:date>
    </item>
    <item>
      <title>Re: Create visit variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-visit-variable/m-p/198398#M305574</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here you go, let me know if I missed a step:&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;infile cards dsd;&lt;/P&gt;&lt;P&gt;informat ID $1.&amp;nbsp;&amp;nbsp;&amp;nbsp; begin_date&amp;nbsp;&amp;nbsp;&amp;nbsp; end_date&amp;nbsp;&amp;nbsp;&amp;nbsp; date1&amp;nbsp;&amp;nbsp;&amp;nbsp; dot1 mmddyy8.;&lt;/P&gt;&lt;P&gt;format ID $1.&amp;nbsp;&amp;nbsp;&amp;nbsp; begin_date&amp;nbsp;&amp;nbsp;&amp;nbsp; end_date&amp;nbsp;&amp;nbsp;&amp;nbsp; date1&amp;nbsp;&amp;nbsp;&amp;nbsp; dot1 mmddyy8.;&lt;/P&gt;&lt;P&gt;input ID&amp;nbsp;&amp;nbsp;&amp;nbsp; begin_date&amp;nbsp;&amp;nbsp;&amp;nbsp; end_date&amp;nbsp;&amp;nbsp;&amp;nbsp; date1&amp;nbsp;&amp;nbsp;&amp;nbsp; dot1;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1,02/12/06,04/29/06,02/12/06,04/29/16&lt;/P&gt;&lt;P&gt;1,03/14/07,01/15/08,03/14/07,04/18/07&lt;/P&gt;&lt;P&gt;1,03/14/07,01/15/08,04/18/07,05/16/07&lt;/P&gt;&lt;P&gt;1,03/14/07,01/15/08,05/16/07,09/02/07&lt;/P&gt;&lt;P&gt;1,03/14/07,01/15/08,09/02/07,01/15/08&lt;/P&gt;&lt;P&gt;1,05/15/10,08/05/12,06/26/10,08/15/10&lt;/P&gt;&lt;P&gt;1,05/15/10,08/05/12,01/20/11,01/25/11&lt;/P&gt;&lt;P&gt;1,05/15/10,08/05/12,02/01/11,08/01/11&lt;/P&gt;&lt;P&gt;1,05/15/10,08/05/12,04/01/12,04/03/12&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;by id begin_date;&lt;/P&gt;&lt;P&gt;if first.begin_date then trip + 1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jul 2015 16:00:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-visit-variable/m-p/198398#M305574</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-07-08T16:00:59Z</dc:date>
    </item>
    <item>
      <title>Re: Create visit variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-visit-variable/m-p/198399#M305575</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;May want to modify Mark's code with a reset for each ID if the idea is to have trips per Id.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;by id begin_date;&lt;/P&gt;&lt;P&gt;if first.id then trip=0; /* reset for each id*/&lt;/P&gt;&lt;P&gt;if first.begin_date then trip + 1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jul 2015 16:19:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-visit-variable/m-p/198399#M305575</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-07-08T16:19:35Z</dc:date>
    </item>
    <item>
      <title>Re: Create visit variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-visit-variable/m-p/198400#M305576</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That was much simpler than I thought, thank you both for your input, the code worked.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jul 2015 16:57:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-visit-variable/m-p/198400#M305576</guid>
      <dc:creator>rfarmenta</dc:creator>
      <dc:date>2015-07-08T16:57:56Z</dc:date>
    </item>
  </channel>
</rss>

