<?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: Handling Date variable in claims data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Handling-Date-variable-in-claims-data/m-p/306513#M312609</link>
    <description>&lt;P&gt;Or, if you prefer a data step (should be more efficient)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data patients;
do until(last.patientid);
	set flagged_claims; by patientId;
	if rx_flag then do;
		firstFillDate = min(firstFillDate, fillDate);
		lastFillDateThru = max(lastFillDateThru, fillDateThru);
		end;
	end;
keep patientId firstFillDate lastFillDateThru;
format firstFillDate lastFillDateThru yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 22 Oct 2016 04:17:35 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2016-10-22T04:17:35Z</dc:date>
    <item>
      <title>Handling Date variable in claims data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-Date-variable-in-claims-data/m-p/306492#M312603</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am currently working with claims dataset. I need to get patient level claims dataset. My dataset looks like:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;ClaimID &amp;nbsp;Patient ID &amp;nbsp;&amp;nbsp;Rxflag &amp;nbsp;Filldate&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;Filldatethru&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;08/09/10 &amp;nbsp; &amp;nbsp; &amp;nbsp;09/08/10&lt;/P&gt;
&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10/08/10 &amp;nbsp; &amp;nbsp; &amp;nbsp;11/09/10&lt;/P&gt;
&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10/08/10 &amp;nbsp; &amp;nbsp; &amp;nbsp;12/13/10&lt;/P&gt;
&lt;P&gt;4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;03/09/11 &amp;nbsp; &amp;nbsp; &amp;nbsp; 05/10/11&lt;/P&gt;
&lt;P&gt;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;06/10/12 &amp;nbsp; &amp;nbsp; &amp;nbsp; 07/13/11 &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to create variables named start_date and end_date based on unique patient ID to capture the date of first and last fill. I tried using something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data PATIENT_LEVEL_EVER_FLAGS (keep=pt_id drug_ever);
	set FLAGGED_CLAIMS;
	by pt_id;
	label drug_ever="Ever have drug code of interest";

	if first.pt_id then
		do;
			drug_ever=0;
		end;

	if rx_flag=1 then
		drug_ever=1;

	if drug_ever=1 then
		startdate=filldate;

	if last.pt_id then
		output;

	if last.pt_id then
		enddate=filldatethru;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am confused with the concept. Could someone please explain me the basics behind this? &amp;nbsp;Any suggestions&amp;nbsp;on how to proceed will be of great help! Thanks.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Oct 2016 03:47:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-Date-variable-in-claims-data/m-p/306492#M312603</guid>
      <dc:creator>san</dc:creator>
      <dc:date>2016-10-22T03:47:02Z</dc:date>
    </item>
    <item>
      <title>Re: Handling Date variable in claims data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-Date-variable-in-claims-data/m-p/306506#M312604</link>
      <description>&lt;P&gt;A better option might be SQL. This should be fairly close:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table patients as
   select patientid
             ,count(*) as patientvisits
             ,min(filldate) as firstfilldate format = date9.
             ,max(filldatethru)  as lastfilldatethru format = date9.
  from flagged_claims
  where rx_flag = 1
  group by patientid
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Oct 2016 03:47:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-Date-variable-in-claims-data/m-p/306506#M312604</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2016-10-22T03:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: Handling Date variable in claims data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-Date-variable-in-claims-data/m-p/306507#M312605</link>
      <description>&lt;P&gt;Based on the sample dataset abouve what would you expect as output?&lt;/P&gt;
&lt;P&gt;And what are you having issues with in your code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hint:&amp;nbsp;Look into RETAIN to keep variable value across rows.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Oct 2016 03:48:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-Date-variable-in-claims-data/m-p/306507#M312605</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-22T03:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: Handling Date variable in claims data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-Date-variable-in-claims-data/m-p/306509#M312606</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;Thanks for your inputs. I expect that the output will have all the variables given in the sample and will create two new variables 'startdate' and 'enddate'. Startdate&amp;nbsp;represents when the first prescription was filled(is equal to filldate). Enddate is when the prescription was stopped(is equal to filldatethru). So, I need to keep start and end dates for each unique patient who was prescribed a drug (whose rx_flag=1). However, when I try running the code which I have mentioned, it gives me missing values for startdate even for rx_flag=1. So, I am not sure how I should be specifying that condition. Should it be&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if rx_flag=1 then startdate=filldate?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will look into the RETAIN statement that you mentioned. Thanks again!&lt;/P&gt;</description>
      <pubDate>Sat, 22 Oct 2016 04:00:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-Date-variable-in-claims-data/m-p/306509#M312606</guid>
      <dc:creator>san</dc:creator>
      <dc:date>2016-10-22T04:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: Handling Date variable in claims data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-Date-variable-in-claims-data/m-p/306511#M312607</link>
      <description>&lt;P&gt;Hi SASKiwi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your input and SQL codes. I will try using this approach to see if it works.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Oct 2016 04:02:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-Date-variable-in-claims-data/m-p/306511#M312607</guid>
      <dc:creator>san</dc:creator>
      <dc:date>2016-10-22T04:02:07Z</dc:date>
    </item>
    <item>
      <title>Re: Handling Date variable in claims data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-Date-variable-in-claims-data/m-p/306512#M312608</link>
      <description>&lt;P&gt;Or, if you want to keep patients without any rx_flag=1 records&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table patients as
   select patientId
             ,count(*) as patientVisits
             ,min(case when rx_flag then filldate else . end) as firstfilldate format = date9.
             ,max(case when rx_flag then filldatethru else . end)  as lastfilldatethru format = date9.
  from flagged_claims
  group by patientId
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Oct 2016 04:09:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-Date-variable-in-claims-data/m-p/306512#M312608</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-10-22T04:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: Handling Date variable in claims data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-Date-variable-in-claims-data/m-p/306513#M312609</link>
      <description>&lt;P&gt;Or, if you prefer a data step (should be more efficient)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data patients;
do until(last.patientid);
	set flagged_claims; by patientId;
	if rx_flag then do;
		firstFillDate = min(firstFillDate, fillDate);
		lastFillDateThru = max(lastFillDateThru, fillDateThru);
		end;
	end;
keep patientId firstFillDate lastFillDateThru;
format firstFillDate lastFillDateThru yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Oct 2016 04:17:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-Date-variable-in-claims-data/m-p/306513#M312609</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-10-22T04:17:35Z</dc:date>
    </item>
    <item>
      <title>Re: Handling Date variable in claims data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-Date-variable-in-claims-data/m-p/306516#M312610</link>
      <description>&lt;P&gt;Hi SASKiwi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The SQL method worked great. It just keeps the observation with RX_flag=1(because of the Where clause). But, I needed to keep all the observations (those without Rx_flag=1 also), hence I modified your method using suggestions made by PGStats.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a ton!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Oct 2016 04:45:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-Date-variable-in-claims-data/m-p/306516#M312610</guid>
      <dc:creator>san</dc:creator>
      <dc:date>2016-10-22T04:45:56Z</dc:date>
    </item>
    <item>
      <title>Re: Handling Date variable in claims data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-Date-variable-in-claims-data/m-p/306517#M312611</link>
      <description>&lt;P&gt;Hello PGStats,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for providing the SQL method for keeping all patient-level&amp;nbsp;observations. It worked perfectly. (I now have start date for every patient who was prescribed the drug and no start date for every patient who was not prescribed the drug).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Sat, 22 Oct 2016 04:49:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-Date-variable-in-claims-data/m-p/306517#M312611</guid>
      <dc:creator>san</dc:creator>
      <dc:date>2016-10-22T04:49:37Z</dc:date>
    </item>
    <item>
      <title>Re: Handling Date variable in claims data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-Date-variable-in-claims-data/m-p/306570#M312613</link>
      <description>&lt;P&gt;Hi San,&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I understand your question correctly, you want startdate = fill date and enddate = fillthrudate when rx_flag = 1 otherwise startdate = filldate.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try the solution below:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data patientrx;
  set filldate ;
  by patient_id;
if rx_flag = 1 then 
  do ;
   startdate = filldate;
   enddate = filldatethru;
   end;
else; do;
  startdate = filldate;
  end;
  format startdate enddate mmddyy9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Oct 2016 20:06:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-Date-variable-in-claims-data/m-p/306570#M312613</guid>
      <dc:creator>shravs</dc:creator>
      <dc:date>2016-10-22T20:06:15Z</dc:date>
    </item>
  </channel>
</rss>

