<?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 indicator if drug taken on same or prior date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/indicator-if-drug-taken-on-same-or-prior-date/m-p/799246#M314251</link>
    <description>&lt;P&gt;Hi everybody,&lt;/P&gt;
&lt;P&gt;I have dataset have below with participants who were given three meds: drug A, drug B and drug C. &lt;BR /&gt;I want to get dataset want below, where if the participant was given either drug on a previous date, &lt;BR /&gt;DRUGA (or DRUGB or DRUGC) then DRUGA (or DRUGB or DRUGC) turns from . to 2.&lt;/P&gt;
&lt;P&gt;If no drug was used on that given date or a prior date then DRUGA (or DRUGB or DRUGC)=0. Otherwise, if drug was used on given date but not on any prior date, then DRUGA(or DRUGB or DRUGC)=1.&lt;/P&gt;
&lt;P&gt;I&amp;nbsp;have&amp;nbsp;figured&amp;nbsp;out&amp;nbsp;a&amp;nbsp;way&amp;nbsp;to&amp;nbsp;do,&amp;nbsp;with&amp;nbsp;code&amp;nbsp;below&amp;nbsp;but&amp;nbsp;I&amp;nbsp;want&amp;nbsp;to&amp;nbsp;know&amp;nbsp;if&amp;nbsp;there's&amp;nbsp;a&amp;nbsp;shorter,&amp;nbsp;&lt;BR /&gt;more&amp;nbsp;efficient/elegant&amp;nbsp;way&amp;nbsp;of&amp;nbsp;programming&amp;nbsp;this.&lt;/P&gt;
&lt;P&gt;Here are my have and want datasets, as well as the code I've come up with.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance for any suggestions!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	length patid $25;
	input patid $ event $ date:mmddyy. diff  med DRUGA DRUGB DRUGC;
	format date mmddyy.;
	datalines;
P001 2 06/07/2017 1 1 . 1 .
P001 1 06/10/2017 . . . . .
P001 1 06/12/2017 . . . . .
P001 1 06/13/2017 . . . . .
P001 1 06/20/2017 . 1 . 1 .
P001 0 06/23/2017 . 1 . . 1
P001 0 06/24/2017 . 1 . . 1
P001 0 06/25/2017 . . . . .
P002 1 07/02/2019 . . . . .
P002 2 07/03/2019 1 1 . 1 .
P002 1 07/06/2019 . 1 1 . .
P002 1 07/10/2019 . . . . .
;
run;



data want;
	length patid $25;
	input patid $ event $ date:mmddyy. DRUGA DRUGB DRUGC;
	format date mmddyy.;
	datalines;
P001 1 06/10/2017 0 2 0
P001 1 06/12/2017 0 2 0
P001 1 06/13/2017 0 2 0
P001 1 06/20/2017 0 1 0
P001 0 06/23/2017 0 2 1
P001 0 06/24/2017 0 2 1
P001 0 06/25/2017 0 2 2
P002 1 07/02/2019 0 0 0
P002 1 07/06/2019 1 2 0
P002 1 07/10/2019 2 2 0
;
run;


data want;
	set have;
	by patid date;
	DRUGA_orig=DRUGA;
	DRUGB_orig=DRUGB;
	DRUGC_orig=DRUGC;

	retain DRUGA_imp DRUGB_imp DRUGC_imp;
	if first.patid then do;
		DRUGA=DRUGA_orig; DRUGA_imp=DRUGA_orig;
		DRUGB=DRUGB_orig; DRUGB_imp=DRUGB_orig;
		DRUGC=DRUGC_orig; DRUGC_imp=DRUGC_orig;
	end;
	array x1 DRUGA DRUGB DRUGC;
	array x2 DRUGA_imp DRUGB_imp DRUGC_imp;

	do i=1 to dim(x1);
		if x1[i]=.  then x1[i]=x2[i];	
		else             x2[i]=x1[i];
	end;
	drop i;

	*recode med indicator from 1 to 2 when drug taken on prior date;
	*recode med indicator from . to 0 when no drug taken prior to, or on the same date;
	array xdo1 DRUGA_orig DRUGB_orig DRUGC_orig;
	array xdo2 DRUGA DRUGB DRUGC;
	do j=1 to dim(xdo1);
		if xdo2[j]=.             then xdo2[j]=0;
		if xdo2[j]=1 &amp;amp; xdo1[j]=. then xdo2[j]=xdo2[j]+1;
	end;
	drop j;
	if diff=1 then delete; *delete EVID=2/diff=1 records;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 01 Mar 2022 03:55:36 GMT</pubDate>
    <dc:creator>Merdock</dc:creator>
    <dc:date>2022-03-01T03:55:36Z</dc:date>
    <item>
      <title>indicator if drug taken on same or prior date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/indicator-if-drug-taken-on-same-or-prior-date/m-p/799246#M314251</link>
      <description>&lt;P&gt;Hi everybody,&lt;/P&gt;
&lt;P&gt;I have dataset have below with participants who were given three meds: drug A, drug B and drug C. &lt;BR /&gt;I want to get dataset want below, where if the participant was given either drug on a previous date, &lt;BR /&gt;DRUGA (or DRUGB or DRUGC) then DRUGA (or DRUGB or DRUGC) turns from . to 2.&lt;/P&gt;
&lt;P&gt;If no drug was used on that given date or a prior date then DRUGA (or DRUGB or DRUGC)=0. Otherwise, if drug was used on given date but not on any prior date, then DRUGA(or DRUGB or DRUGC)=1.&lt;/P&gt;
&lt;P&gt;I&amp;nbsp;have&amp;nbsp;figured&amp;nbsp;out&amp;nbsp;a&amp;nbsp;way&amp;nbsp;to&amp;nbsp;do,&amp;nbsp;with&amp;nbsp;code&amp;nbsp;below&amp;nbsp;but&amp;nbsp;I&amp;nbsp;want&amp;nbsp;to&amp;nbsp;know&amp;nbsp;if&amp;nbsp;there's&amp;nbsp;a&amp;nbsp;shorter,&amp;nbsp;&lt;BR /&gt;more&amp;nbsp;efficient/elegant&amp;nbsp;way&amp;nbsp;of&amp;nbsp;programming&amp;nbsp;this.&lt;/P&gt;
&lt;P&gt;Here are my have and want datasets, as well as the code I've come up with.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance for any suggestions!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	length patid $25;
	input patid $ event $ date:mmddyy. diff  med DRUGA DRUGB DRUGC;
	format date mmddyy.;
	datalines;
P001 2 06/07/2017 1 1 . 1 .
P001 1 06/10/2017 . . . . .
P001 1 06/12/2017 . . . . .
P001 1 06/13/2017 . . . . .
P001 1 06/20/2017 . 1 . 1 .
P001 0 06/23/2017 . 1 . . 1
P001 0 06/24/2017 . 1 . . 1
P001 0 06/25/2017 . . . . .
P002 1 07/02/2019 . . . . .
P002 2 07/03/2019 1 1 . 1 .
P002 1 07/06/2019 . 1 1 . .
P002 1 07/10/2019 . . . . .
;
run;



data want;
	length patid $25;
	input patid $ event $ date:mmddyy. DRUGA DRUGB DRUGC;
	format date mmddyy.;
	datalines;
P001 1 06/10/2017 0 2 0
P001 1 06/12/2017 0 2 0
P001 1 06/13/2017 0 2 0
P001 1 06/20/2017 0 1 0
P001 0 06/23/2017 0 2 1
P001 0 06/24/2017 0 2 1
P001 0 06/25/2017 0 2 2
P002 1 07/02/2019 0 0 0
P002 1 07/06/2019 1 2 0
P002 1 07/10/2019 2 2 0
;
run;


data want;
	set have;
	by patid date;
	DRUGA_orig=DRUGA;
	DRUGB_orig=DRUGB;
	DRUGC_orig=DRUGC;

	retain DRUGA_imp DRUGB_imp DRUGC_imp;
	if first.patid then do;
		DRUGA=DRUGA_orig; DRUGA_imp=DRUGA_orig;
		DRUGB=DRUGB_orig; DRUGB_imp=DRUGB_orig;
		DRUGC=DRUGC_orig; DRUGC_imp=DRUGC_orig;
	end;
	array x1 DRUGA DRUGB DRUGC;
	array x2 DRUGA_imp DRUGB_imp DRUGC_imp;

	do i=1 to dim(x1);
		if x1[i]=.  then x1[i]=x2[i];	
		else             x2[i]=x1[i];
	end;
	drop i;

	*recode med indicator from 1 to 2 when drug taken on prior date;
	*recode med indicator from . to 0 when no drug taken prior to, or on the same date;
	array xdo1 DRUGA_orig DRUGB_orig DRUGC_orig;
	array xdo2 DRUGA DRUGB DRUGC;
	do j=1 to dim(xdo1);
		if xdo2[j]=.             then xdo2[j]=0;
		if xdo2[j]=1 &amp;amp; xdo1[j]=. then xdo2[j]=xdo2[j]+1;
	end;
	drop j;
	if diff=1 then delete; *delete EVID=2/diff=1 records;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Mar 2022 03:55:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/indicator-if-drug-taken-on-same-or-prior-date/m-p/799246#M314251</guid>
      <dc:creator>Merdock</dc:creator>
      <dc:date>2022-03-01T03:55:36Z</dc:date>
    </item>
    <item>
      <title>Re: indicator if drug taken on same or prior date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/indicator-if-drug-taken-on-same-or-prior-date/m-p/799260#M314263</link>
      <description>&lt;P&gt;A few questions :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Can a patient receive more than 1 drug in 1 obs ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Do you want to delete all obs from &lt;STRONG&gt;have&amp;nbsp;&lt;/STRONG&gt;where diff = 1?&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 08:41:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/indicator-if-drug-taken-on-same-or-prior-date/m-p/799260#M314263</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-03-01T08:41:54Z</dc:date>
    </item>
    <item>
      <title>Re: indicator if drug taken on same or prior date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/indicator-if-drug-taken-on-same-or-prior-date/m-p/799330#M314303</link>
      <description>&lt;P&gt;1) Yes, a participant can receive more than 1 drug in 1 obs&lt;/P&gt;
&lt;P&gt;2) Yes, the final dataset should only contain patid, evid, date and the drug indicators.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your follow-up!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 15:12:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/indicator-if-drug-taken-on-same-or-prior-date/m-p/799330#M314303</guid>
      <dc:creator>Merdock</dc:creator>
      <dc:date>2022-03-01T15:12:22Z</dc:date>
    </item>
  </channel>
</rss>

