<?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 How to Locate Where a Date Should Fall in a Vertacle Date Range in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Locate-Where-a-Date-Should-Fall-in-a-Vertacle-Date-Range/m-p/284857#M58137</link>
    <description>&lt;P&gt;I have a scenario that I have been coming across more and more often. &amp;nbsp;I figured now is the time to see if there is a more efficient way to do what I want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Suppose I have 2 tables: an adverse event table and a visit table (see below for examples). &amp;nbsp;I might want to take the date that an AE&amp;nbsp;occurred (AEDT) and see in which cycle of the study the AE occurred.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;SUBJID	  AEDT	        TERM&lt;/STRONG&gt;
001-001	  1/7/2016	Nausea
001-001	  1/9/2016	Headache
001-001	  2/4/2016	Vomiting&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;SUBJID	VISITDT	        TIMEPT	CYCLE	DAY&lt;/STRONG&gt;
001-001	1/4/2016	C1D1	1	1
001-001	1/11/2016	C1D8	1	8
001-001	1/18/2016	C1D15	1	15
001-001	1/25/2016	C2D1	2	1
001-001	2/1/2016	C2D8	2	8
001-001	2/8/2016	C2D15	2	15&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;From the info above, I can eyeball&amp;nbsp;that the first 2 events occurred in Cycle 1 while the third event occurred in Cycle 2. &amp;nbsp;Would SQL help me find those proper placements? &amp;nbsp;Currently, I am taking the visit table and transposing it so that there is a column for each visit (just keeping the CxD1 dates). &amp;nbsp;Then I merge it in with the AE table (see example table below) and loop through every visit column and check if AEDT is between&amp;nbsp;[C1D1 and&amp;nbsp;C2D1) or [C2D1 and C3D1) (and so on for each cycle visit available). &amp;nbsp;This seems very ineffective. &amp;nbsp;Is there a better way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;SUBJID	AEDT	   TERM	        C1D1	   C2D1&lt;/STRONG&gt;
001-001	1/7/2016   Nausea	1/4/2016   1/25/2016
001-001	1/9/2016   Headache	1/4/2016   1/25/2016
001-001	2/4/2016   Vomiting	1/4/2016   1/25/2016&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Jul 2016 15:45:00 GMT</pubDate>
    <dc:creator>djbateman</dc:creator>
    <dc:date>2016-07-15T15:45:00Z</dc:date>
    <item>
      <title>How to Locate Where a Date Should Fall in a Vertacle Date Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Locate-Where-a-Date-Should-Fall-in-a-Vertacle-Date-Range/m-p/284857#M58137</link>
      <description>&lt;P&gt;I have a scenario that I have been coming across more and more often. &amp;nbsp;I figured now is the time to see if there is a more efficient way to do what I want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Suppose I have 2 tables: an adverse event table and a visit table (see below for examples). &amp;nbsp;I might want to take the date that an AE&amp;nbsp;occurred (AEDT) and see in which cycle of the study the AE occurred.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;SUBJID	  AEDT	        TERM&lt;/STRONG&gt;
001-001	  1/7/2016	Nausea
001-001	  1/9/2016	Headache
001-001	  2/4/2016	Vomiting&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;SUBJID	VISITDT	        TIMEPT	CYCLE	DAY&lt;/STRONG&gt;
001-001	1/4/2016	C1D1	1	1
001-001	1/11/2016	C1D8	1	8
001-001	1/18/2016	C1D15	1	15
001-001	1/25/2016	C2D1	2	1
001-001	2/1/2016	C2D8	2	8
001-001	2/8/2016	C2D15	2	15&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;From the info above, I can eyeball&amp;nbsp;that the first 2 events occurred in Cycle 1 while the third event occurred in Cycle 2. &amp;nbsp;Would SQL help me find those proper placements? &amp;nbsp;Currently, I am taking the visit table and transposing it so that there is a column for each visit (just keeping the CxD1 dates). &amp;nbsp;Then I merge it in with the AE table (see example table below) and loop through every visit column and check if AEDT is between&amp;nbsp;[C1D1 and&amp;nbsp;C2D1) or [C2D1 and C3D1) (and so on for each cycle visit available). &amp;nbsp;This seems very ineffective. &amp;nbsp;Is there a better way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;SUBJID	AEDT	   TERM	        C1D1	   C2D1&lt;/STRONG&gt;
001-001	1/7/2016   Nausea	1/4/2016   1/25/2016
001-001	1/9/2016   Headache	1/4/2016   1/25/2016
001-001	2/4/2016   Vomiting	1/4/2016   1/25/2016&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2016 15:45:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Locate-Where-a-Date-Should-Fall-in-a-Vertacle-Date-Range/m-p/284857#M58137</guid>
      <dc:creator>djbateman</dc:creator>
      <dc:date>2016-07-15T15:45:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to Locate Where a Date Should Fall in a Vertacle Date Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Locate-Where-a-Date-Should-Fall-in-a-Vertacle-Date-Range/m-p/284893#M58142</link>
      <description>&lt;P&gt;You could merge the two datasets:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Assume both datasets are sorted by SUBJID and date */
data eventCycles;
retain currentCycle;
merge 
    events(rename=AEDT=date in=event)
    visits(rename=VISITDT=date);
by SUBJID date;
if first.SUBJID then call missing(currentCycle); /* In case there is no visit */
if not missing(cycle) then currentCycle = cycle;
if event then output;
keep SUBJID date currentCycle TERM; 
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Jul 2016 17:17:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Locate-Where-a-Date-Should-Fall-in-a-Vertacle-Date-Range/m-p/284893#M58142</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-07-15T17:17:30Z</dc:date>
    </item>
  </channel>
</rss>

