<?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: Getting data that occurred between two dates for a specific person in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Getting-data-that-occurred-between-two-dates-for-a-specific/m-p/607423#M176589</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input NAME	$ (DATE_IN	DATE_OUT) (:yymmdd10.)	VALUE;
format DATE_IN	DATE_OUT yymmdd10.;
cards;
bob	20190519	20190601	5
jerry	20190306	20190324	11
tim	20190822	20190824	18
;

data have2;
input NAME $	DATE :yymmdd10.	VALUE;
format date yymmdd10.;
cards;
bob	20190522	7
bob	20190528	14
bob	20190615	3
;

proc sql;
create table want as
select b.*
from have a, have2 b
where a.name=b.name and date_in&amp;lt;=date&amp;lt;=date_out;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 26 Nov 2019 16:48:47 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-11-26T16:48:47Z</dc:date>
    <item>
      <title>Getting data that occurred between two dates for a specific person</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-data-that-occurred-between-two-dates-for-a-specific/m-p/607418#M176586</link>
      <description>&lt;P&gt;Okay lets say I have This data set&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;NAME&lt;/TD&gt;&lt;TD&gt;DATE IN&lt;/TD&gt;&lt;TD&gt;DATE OUT&lt;/TD&gt;&lt;TD&gt;VALUE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;bob&lt;/TD&gt;&lt;TD&gt;20190519&lt;/TD&gt;&lt;TD&gt;20190601&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;jerry&lt;/TD&gt;&lt;TD&gt;20190306&lt;/TD&gt;&lt;TD&gt;20190324&lt;/TD&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;tim&lt;/TD&gt;&lt;TD&gt;20190822&lt;/TD&gt;&lt;TD&gt;20190824&lt;/TD&gt;&lt;TD&gt;18&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My goal is to get other rows of data that occurs between the DATE IN and DATE OUT for each person. So if I also have this other table that contains this data for bob&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;NAME&lt;/TD&gt;&lt;TD&gt;DATE&lt;/TD&gt;&lt;TD&gt;VALUE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;bob&lt;/TD&gt;&lt;TD&gt;20190522&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;bob&lt;/TD&gt;&lt;TD&gt;20190528&lt;/TD&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;bob&lt;/TD&gt;&lt;TD&gt;20190615&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to be able to bring in the first two rows of data since they occured between the dates for bob from the first table, but not the third row since it occurred outside the DATE IN and DATE OUT. Please let me know if that doesn't make sense!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought about creating a macro variable that contained all dates between DATE IN and DATE OUT for bob and then using WHERE DATE IN (Macro Variable attached to bob's dates), but couldnt figure out how to get all dates between those two spots.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lastly, my dates are SAS dates so I was using input(put(PREV_DSCHRG, yymmddn8.), 8.) to get them to numeric date values, please let me know if there's a better way to do this!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 16:41:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-data-that-occurred-between-two-dates-for-a-specific/m-p/607418#M176586</guid>
      <dc:creator>mhoward2</dc:creator>
      <dc:date>2019-11-26T16:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: Getting data that occurred between two dates for a specific person</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-data-that-occurred-between-two-dates-for-a-specific/m-p/607421#M176587</link>
      <description>&lt;P&gt;Here is one way. What should happen if the name is not present in the first data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input name $ (datein dateout)(:anydtdte.) value;
format datein dateout yymmddn8.;
datalines;
bob 20190519 20190601 5
jerry 20190306 20190324 11
tim 20190822 20190824 18
;

data two;
input name $ date :anydtdte. value;
format date yymmddn8.;
datalines;
bob 20190522 5
bob 20190528 11
bob 20190615 18
;

data want(drop=datein dateout rc);
   if _N_=1 then do;
      declare hash h(dataset:'one');
      h.definekey('name');
      h.definedata('datein', 'dateout');
      h.definedone();
   end;

   set two;
   datein=.; dateout=.;

   rc=h.find();

   if datein &amp;lt;= date &amp;lt;= dateout;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 16:45:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-data-that-occurred-between-two-dates-for-a-specific/m-p/607421#M176587</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-11-26T16:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: Getting data that occurred between two dates for a specific person</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-data-that-occurred-between-two-dates-for-a-specific/m-p/607422#M176588</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have1;
input NAME	$ DATE_IN:anydtdte. DATE_OUT :anydtdte.	VALUE;
format DATE_IN DATE_OUT date9.;
cards;
bob 20190519 20190601 5
jerry 20190306 20190324 11
tim 20190822 20190824 18
;
run;

data have2;
input NAME $ DATE :anydtdte. VALUE;
format DATE date9.;
cards;
bob 20190522 5
bob 20190528 11
bob 20190615 18
;
run;


data want;
	merge have1 have2;
	by name;

	if DATE_IN &amp;lt;= DATE &amp;lt;= DATE_OUT;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Nov 2019 16:45:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-data-that-occurred-between-two-dates-for-a-specific/m-p/607422#M176588</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2019-11-26T16:45:50Z</dc:date>
    </item>
    <item>
      <title>Re: Getting data that occurred between two dates for a specific person</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-data-that-occurred-between-two-dates-for-a-specific/m-p/607423#M176589</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input NAME	$ (DATE_IN	DATE_OUT) (:yymmdd10.)	VALUE;
format DATE_IN	DATE_OUT yymmdd10.;
cards;
bob	20190519	20190601	5
jerry	20190306	20190324	11
tim	20190822	20190824	18
;

data have2;
input NAME $	DATE :yymmdd10.	VALUE;
format date yymmdd10.;
cards;
bob	20190522	7
bob	20190528	14
bob	20190615	3
;

proc sql;
create table want as
select b.*
from have a, have2 b
where a.name=b.name and date_in&amp;lt;=date&amp;lt;=date_out;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Nov 2019 16:48:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-data-that-occurred-between-two-dates-for-a-specific/m-p/607423#M176589</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-11-26T16:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: Getting data that occurred between two dates for a specific person</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-data-that-occurred-between-two-dates-for-a-specific/m-p/607424#M176590</link>
      <description>&lt;P&gt;You already had SAS dates and converted them to this useless ****?&lt;/P&gt;
&lt;P&gt;That's like giving away your Ferrari for a Trabant and being happy about it.&lt;/P&gt;
&lt;P&gt;You only need to do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select
  t1.name,
  t1.date_in,
  t1.date_out,
  t1.value as value_1,
  t2.date,
  t2.value as value2
from have1 t1, have2 t2
where t1.name = t2.name and t2.date between t1.date_in and t2.date_out
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and keep the SAS dates, for $DEITY's sake!&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 16:49:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-data-that-occurred-between-two-dates-for-a-specific/m-p/607424#M176590</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-11-26T16:49:58Z</dc:date>
    </item>
    <item>
      <title>Re: Getting data that occurred between two dates for a specific person</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-data-that-occurred-between-two-dates-for-a-specific/m-p/607427#M176593</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/279427"&gt;@mhoward2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lastly, my dates are SAS dates so I was using input(put(PREV_DSCHRG, yymmddn8.), 8.) to get them to numeric date values, please let me know if there's a better way to do this!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That does NOT&amp;nbsp; create a SAS date value, it creates a numeric value that mimics a SAS date value. For put(PREV_DSCHRG, yymmddn8.) to have&amp;nbsp;created expected values then&amp;nbsp;your&amp;nbsp;&amp;nbsp;PREV_DSCHRG variable started out as a SAS date variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your Datein or Dateout variables were created this way you may want to test:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; year = year(datein);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;and see if the Year values are the expected year for Datein.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many comparisons may work but if you want to do anything with actual intervals or graphing of these dates you may not like the results.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 16:55:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-data-that-occurred-between-two-dates-for-a-specific/m-p/607427#M176593</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-11-26T16:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: Getting data that occurred between two dates for a specific person</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-data-that-occurred-between-two-dates-for-a-specific/m-p/610104#M177646</link>
      <description>I know this was awhile ago but this worked great for me, thanks!</description>
      <pubDate>Fri, 06 Dec 2019 20:40:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-data-that-occurred-between-two-dates-for-a-specific/m-p/610104#M177646</guid>
      <dc:creator>mhoward2</dc:creator>
      <dc:date>2019-12-06T20:40:16Z</dc:date>
    </item>
  </channel>
</rss>

