<?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: Claims file with several lines per ID: identify claims during pregnancy defined in separate file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Claims-file-with-several-lines-per-ID-identify-claims-during/m-p/807624#M318445</link>
    <description>Thanks a lot, I'll implement this tomorrow to check if it works in my dataset! Always great to learn something new!</description>
    <pubDate>Wed, 13 Apr 2022 15:20:17 GMT</pubDate>
    <dc:creator>jspoend</dc:creator>
    <dc:date>2022-04-13T15:20:17Z</dc:date>
    <item>
      <title>Claims file with several lines per ID: identify claims during pregnancy defined in separate file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Claims-file-with-several-lines-per-ID-identify-claims-during/m-p/807599#M318430</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two datasets:&lt;/P&gt;&lt;P&gt;1) all health care claims (drugs) of women who delivered during the study period (2015-2021)&lt;/P&gt;&lt;P&gt;2) pregnancy file&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The two files are structured as follows:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Claims file:&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;ID date_claim claim_code&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 1JAN2015 ATC1&lt;/P&gt;&lt;P&gt;1 20FEB2015 ATC2&lt;/P&gt;&lt;P&gt;1 15JUL2016 ATC3&lt;/P&gt;&lt;P&gt;1 20SEP2017 ATC2&lt;/P&gt;&lt;P&gt;2 3JAN2017 ATC7&lt;/P&gt;&lt;P&gt;2 5FEB2018 ATC1&lt;/P&gt;&lt;P&gt;2 8MAR2019 ATC11&lt;/P&gt;&lt;P&gt;2 15AUG2020 ATC12&lt;/P&gt;&lt;P&gt;2 20DEC2021 ATC11&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Pregnancy file:&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;ID pregnancy_start pregnancy_end&lt;/P&gt;&lt;P&gt;1 29JAN2017 28OCT2017&lt;/P&gt;&lt;P&gt;2 30JAN2018 15OCT2018&lt;/P&gt;&lt;P&gt;2 25JUN2020 15MAR2021&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My goal is to 1) combine the two datasets and to 2) exclude all claims that were not billed during a pregnancy and to 3) create a new ID per pregnancy (bc one patient may have contributed several pregnancies - so the analytic unit will be pregnancy not ID).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure how to go about this - I'm mainly struggling with step 2. My first attempt was to combine the two datasets with a set command and then to impute the pregnancy_start and pregnancy_end for all lines in the dataset using the retain fuction by ID. However, given that one patient can contribute several pregnancies that does not work. I'm a bit stuck right now, so any input is appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot in advance! Julia&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2022 14:12:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Claims-file-with-several-lines-per-ID-identify-claims-during/m-p/807599#M318430</guid>
      <dc:creator>jspoend</dc:creator>
      <dc:date>2022-04-13T14:12:51Z</dc:date>
    </item>
    <item>
      <title>Re: Claims file with several lines per ID: identify claims during pregnancy defined in separate file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Claims-file-with-several-lines-per-ID-identify-claims-during/m-p/807608#M318432</link>
      <description>&lt;P&gt;This is untested, in the absence of sample data in the form of a working DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_:);
  set pregnancy (keep=id pregnancy_start rename=(pregnancy_start=_refdate) in=inpreg)
      claims    (keep=id date_claim      rename=(date_claim=_refdate)      in=inclaim);

  by id _refdate;
  if inpreg then do;
    if id=lag(id) then preg_seq+1;
    else preg_seq=1;
    set pregnancy;
  end;
  if inclaim=1 then do;
    set claims;
    if pregnancy_start&amp;lt;=date_claim&amp;lt;=pregnancy_end then output;
  end;
  if last.id then call missing(of _all_);    *Added later, see note **;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This assumes that dataset PREGNANCY is sorted by ID/PREGNANCY_START and CLAIMS is sorted by ID/DATE_CLAIM.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first set statement establishes a sorted interleaving of the observations from the two data sets, but keeps only the two variables needed to validate the sort order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the two-variable obs-in-hand is a pregrancy obs, then SET the entire observation.&amp;nbsp; The pregnancy variables will be retained across many CLAIMS obs until the next pregnancy obs.&amp;nbsp; This is also an opportunity to make the new PREG_SEQ variable (for first pregnancy, second, .... etc.).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if the two-variable obs-in-hand is a CLAIMS obs, then read in the whole obs, check its date against the pregnancy dates, and output accordingly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE:&amp;nbsp; I added the "if last.id then call missing(of _all_);" to prevent a pre-first-pregnancy claim from a given ID from accidentally qualifying in the date range of the last pregnancy of the prior ID.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2022 15:16:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Claims-file-with-several-lines-per-ID-identify-claims-during/m-p/807608#M318432</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-04-13T15:16:59Z</dc:date>
    </item>
    <item>
      <title>Re: Claims file with several lines per ID: identify claims during pregnancy defined in separate file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Claims-file-with-several-lines-per-ID-identify-claims-during/m-p/807613#M318437</link>
      <description>&lt;P&gt;Simple solution: first, create the sequence number, then join with SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data claims;
input ID $ date_claim :date9. claim_code $;
format date_claim yymmdd10.;
datalines; 
1 1JAN2015 ATC1
1 20FEB2015 ATC2
1 15JUL2016 ATC3
1 20SEP2017 ATC2
2 3JAN2017 ATC7
2 5FEB2018 ATC1
2 8MAR2019 ATC11
2 15AUG2020 ATC12
2 20DEC2021 ATC11
;

data pregnancy;
input ID $ (pregnancy_start pregnancy_end) (:date9.);
format pregnancy_start pregnancy_end yymmdd10.;
datalines;
1 29JAN2017 28OCT2017
2 30JAN2018 15OCT2018
2 25JUN2020 15MAR2021
;

data pregnancy_seq;
set pregnancy;
by id;
if first.id
then seq = 1;
else seq + 1;
run;

proc sql;
create table want as
  select
    t1.*,
    t2.date_claim,
    t2.claim_code
  from pregnancy t1 left join claims t2
  on t1.id = t2.id and t1.pregnancy_start le t2.date_claim le t1.pregnancy_end
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Apr 2022 14:57:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Claims-file-with-several-lines-per-ID-identify-claims-during/m-p/807613#M318437</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-13T14:57:47Z</dc:date>
    </item>
    <item>
      <title>Re: Claims file with several lines per ID: identify claims during pregnancy defined in separate file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Claims-file-with-several-lines-per-ID-identify-claims-during/m-p/807619#M318440</link>
      <description>Hi Kurt,&lt;BR /&gt;&lt;BR /&gt;Thanks a lot for the fast reply. I'm struggling to understand: how would I combine the two if I only create the sequence number in the pregnancy file? Then I could still not identify which claims from the claims file belong to this pregnancy, or do I misunderstand?</description>
      <pubDate>Wed, 13 Apr 2022 15:09:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Claims-file-with-several-lines-per-ID-identify-claims-during/m-p/807619#M318440</guid>
      <dc:creator>jspoend</dc:creator>
      <dc:date>2022-04-13T15:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: Claims file with several lines per ID: identify claims during pregnancy defined in separate file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Claims-file-with-several-lines-per-ID-identify-claims-during/m-p/807622#M318443</link>
      <description>&lt;P&gt;I made a mistake when posting, the SQL needs to use the "sequenced" dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    t1.*,
    t2.date_claim,
    t2.claim_code
  from pregnancy_seq t1 left join claims t2
  on t1.id = t2.id and t1.pregnancy_start le t2.date_claim le t1.pregnancy_end
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Both queries create the same observations, just that the sequence number was missing in the previous code. But you could still identify pregnancies by start and end dates.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2022 15:16:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Claims-file-with-several-lines-per-ID-identify-claims-during/m-p/807622#M318443</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-13T15:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: Claims file with several lines per ID: identify claims during pregnancy defined in separate file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Claims-file-with-several-lines-per-ID-identify-claims-during/m-p/807623#M318444</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Thanks a lot for this, I just implemented the code and it seems to do what I want it to do. Many thanks! That made my life a lot easier:)</description>
      <pubDate>Wed, 13 Apr 2022 15:18:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Claims-file-with-several-lines-per-ID-identify-claims-during/m-p/807623#M318444</guid>
      <dc:creator>jspoend</dc:creator>
      <dc:date>2022-04-13T15:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: Claims file with several lines per ID: identify claims during pregnancy defined in separate file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Claims-file-with-several-lines-per-ID-identify-claims-during/m-p/807624#M318445</link>
      <description>Thanks a lot, I'll implement this tomorrow to check if it works in my dataset! Always great to learn something new!</description>
      <pubDate>Wed, 13 Apr 2022 15:20:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Claims-file-with-several-lines-per-ID-identify-claims-during/m-p/807624#M318445</guid>
      <dc:creator>jspoend</dc:creator>
      <dc:date>2022-04-13T15:20:17Z</dc:date>
    </item>
    <item>
      <title>Re: Claims file with several lines per ID: identify claims during pregnancy defined in separate file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Claims-file-with-several-lines-per-ID-identify-claims-during/m-p/811035#M319882</link>
      <description>Thanks Garnet, for the later added line, that did in fact sovle a problem I found in my data!</description>
      <pubDate>Mon, 02 May 2022 10:37:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Claims-file-with-several-lines-per-ID-identify-claims-during/m-p/811035#M319882</guid>
      <dc:creator>jspoend</dc:creator>
      <dc:date>2022-05-02T10:37:22Z</dc:date>
    </item>
  </channel>
</rss>

