<?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: Calculate time difference with duplicates and exclusions in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Calculate-time-difference-with-duplicates-and-exclusions/m-p/741937#M29165</link>
    <description>&lt;P&gt;As long as the key to removing the error records is for a single case number you can not have repeats of the entry_date then the following should work. This is using &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/p181g1p4bw3phkn1vt5p67xvynd5.htm" target="_self"&gt;FIRST. and LAST. DATA Step Variables&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data got ;
	infile cards ;
	input casenum $ entry_date mmddyy8. release_date mmddyy8. ;
cards ;
11118 01/02/19 02/01/19
11119 01/01/19 01/29/19
11120 01/01/19 01/05/19
11120 01/01/19 01/17/19
11120 01/01/19 01/22/19
;

proc sort data=got out=srtdGot ;
	by casenum entry_date ;
run ;

data want rejected ;
	set srtdGot ;
	by casenum entry_date ;
	if first.entry_date and last.entry_date then
		output want ;
	else
		output rejected ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 17 May 2021 17:39:48 GMT</pubDate>
    <dc:creator>AMSAS</dc:creator>
    <dc:date>2021-05-17T17:39:48Z</dc:date>
    <item>
      <title>Calculate time difference with duplicates and exclusions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculate-time-difference-with-duplicates-and-exclusions/m-p/741934#M29164</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am working with a dataset that tracks entry and exit dates per individual, with each individual having a unique identifying number. In most instances, the individual only has a single record, however several individuals have multiple entry and exit dates. I am trying to calculate the number of days each individual is in the program by adding the difference between each release and entry date. The data looks like this:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;casenum&lt;/TD&gt;&lt;TD&gt;entry_date&lt;/TD&gt;&lt;TD&gt;release_date&lt;/TD&gt;&lt;TD&gt;counter&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11111&lt;/TD&gt;&lt;TD&gt;1/2/2019&lt;/TD&gt;&lt;TD&gt;1/3/2019&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11111&lt;/TD&gt;&lt;TD&gt;1/17/2019&lt;/TD&gt;&lt;TD&gt;1/21/2019&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11112&lt;/TD&gt;&lt;TD&gt;1/1/2019&lt;/TD&gt;&lt;TD&gt;1/6/2019&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11113&lt;/TD&gt;&lt;TD&gt;1/2/2019&lt;/TD&gt;&lt;TD&gt;1/5/2019&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11114&lt;/TD&gt;&lt;TD&gt;1/1/2019&lt;/TD&gt;&lt;TD&gt;1/3/2019&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11114&lt;/TD&gt;&lt;TD&gt;1/9/2019&lt;/TD&gt;&lt;TD&gt;1/15/2019&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11114&lt;/TD&gt;&lt;TD&gt;1/17/2019&lt;/TD&gt;&lt;TD&gt;1/18/2019&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&l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D&gt;&lt;TD&gt;1/5/2019&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11120&lt;/TD&gt;&lt;TD&gt;1/1/2019&lt;/TD&gt;&lt;TD&gt;1/17/2019&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11120&lt;/TD&gt;&lt;TD&gt;1/1/2019&lt;/TD&gt;&lt;TD&gt;1/22/2019&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I was given the variables casenum, entry_date, and release_date. The counter variable was something I created. As I mentioned earlier, I need to calculate the number of days between each entry and release date per person. However, the snag I have run into is that I need to exclude cases like 11120, where a single entry date has multiple release dates; these need to be left as missing when I calculate the time duration. I would prefer to write the program such that the program drops ALL observations of the case number 11120 based on the existence of duplicate entry dates, rather than by using the precise case number (I am trying to limit my hard coding to avoid having to update it every time we receive new data). Is there an efficient way to go about 1) dropping the observations that need to be dropped and 2) adding the total time for the rest? Any advice is appreciated!&lt;/P&gt;</description>
      <pubDate>Mon, 17 May 2021 17:21:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculate-time-difference-with-duplicates-and-exclusions/m-p/741934#M29164</guid>
      <dc:creator>MHines</dc:creator>
      <dc:date>2021-05-17T17:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate time difference with duplicates and exclusions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculate-time-difference-with-duplicates-and-exclusions/m-p/741937#M29165</link>
      <description>&lt;P&gt;As long as the key to removing the error records is for a single case number you can not have repeats of the entry_date then the following should work. This is using &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/p181g1p4bw3phkn1vt5p67xvynd5.htm" target="_self"&gt;FIRST. and LAST. DATA Step Variables&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data got ;
	infile cards ;
	input casenum $ entry_date mmddyy8. release_date mmddyy8. ;
cards ;
11118 01/02/19 02/01/19
11119 01/01/19 01/29/19
11120 01/01/19 01/05/19
11120 01/01/19 01/17/19
11120 01/01/19 01/22/19
;

proc sort data=got out=srtdGot ;
	by casenum entry_date ;
run ;

data want rejected ;
	set srtdGot ;
	by casenum entry_date ;
	if first.entry_date and last.entry_date then
		output want ;
	else
		output rejected ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 May 2021 17:39:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculate-time-difference-with-duplicates-and-exclusions/m-p/741937#M29165</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2021-05-17T17:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate time difference with duplicates and exclusions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculate-time-difference-with-duplicates-and-exclusions/m-p/741941#M29166</link>
      <description>That worked, thank you!</description>
      <pubDate>Mon, 17 May 2021 17:58:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculate-time-difference-with-duplicates-and-exclusions/m-p/741941#M29166</guid>
      <dc:creator>MHines</dc:creator>
      <dc:date>2021-05-17T17:58:05Z</dc:date>
    </item>
  </channel>
</rss>

