BookmarkSubscribeRSS Feed
deleted_user
Not applicable
How to check programmatically if patient is taking medications more than 3 times a week? Patient ID, drug name and dates are known.

Thanks,
Eugene
7 REPLIES 7
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Using DATE, create a WEEK_START date using the INTNX function. Then use a SAS PROC (SUMMARY, MEANS), as required, for aggregation and analysis.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

intnx function site:sas.com

Related DOC:
http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001304321.htm Message was edited by: sbb
deleted_user
Not applicable
Hi SBB,
please see data below, I need to have a list of ID/DRUG/DATE, that have taken the same drug more than 3 times a week. Thank you for you help.

ID DRUG DATE
100001 ADVIL 2010-03-25
100001 TILENOL 2010-04-08
100001 TILENOL 2010-04-10
100001 TILENOL 2010-04-12
100001 TILENOL 2010-04-14
100001 TILENOL 2010-04-28
100001 TILENOL 2010-05-01
100002 ADVIL 2010-04-01
100002 ADVIL 2010-04-09
100002 ADVIL 2010-04-10
100002 ADVIL 2010-04-12
100002 ADVIL 2010-04-14
100002 TILENOL 2010-04-28
100002 TILENOL 2010-05-01
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Suggest you have a look at some SAS DOC on DATA step programming to get you started with learning SAS Base programming skills, my friend.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

data step programming site:sas.com

data step input data site:sas.com
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello Evolod,

This is a possible solution to your problem. For the data you supplied all patients took less than 3 medications a week.

data a;
input ID 1-6 DRUG $ 8-14 DATE YYMMDD11.;
format date date7.;
datalines;
100001 ADVIL 2010-03-25
100001 TILENOL 2010-04-08
100001 TILENOL 2010-04-10
100001 TILENOL 2010-04-12
100001 TILENOL 2010-04-14
100001 TILENOL 2010-04-28
100001 TILENOL 2010-05-01
100002 ADVIL 2010-04-01
100002 ADVIL 2010-04-09
100002 ADVIL 2010-04-10
100002 ADVIL 2010-04-12
100002 ADVIL 2010-04-14
100002 TILENOL 2010-04-28
100002 TILENOL 2010-05-01
;
run;
/* Add Year, Week */;
data a1;
set a;
yr=YEAR(Date);
wk=WEEK(Date);
run;
/* Check if patient is taking meds more that 3 times a week */;
proc SQL;
create table r as
select ID, yr, wk, Count(*) as n,
case
when calculated n > 3 then ' >3'
else '<=3'
end as result
from a1
group by ID, yr, wk
;quit;

Sincerely,
SPR
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Sorry, part of the code has been cut by forum software. It does not like apostrophes.
This is the last proc SQL:

proc SQL;
create table r as
select ID, yr, wk, Count(*) as n,
case
when calculated n > 3 then 'n GT 3'
else 'n LE 3'
end as result
from a1
group by ID, yr, wk
;quit;

SPR
Cynthia_sas
SAS Super FREQ
Hi:
The issue is not the apostrophe, it is the < or > symbol. When you post to the forum using the posting mechanism, the < and > symbols, in particular, look like HTML tags. So you have to "hide" them from being mis-interpreted as HTML tags.

This previous forum posting:
http://support.sas.com/forums/thread.jspa?messageID=27609毙

explains how to use the &lt; and &gt; coding (for < and > respectively) to stop those symbols from being treated as HTML and truncating your posts.

cynthia
sivaji
Fluorite | Level 6
This program will check before 7 days for each record's date and if the count is ge 3 then will print the patient id and drug name corresponding to it.

data pat;
input ID DRUG : $10. d_DATE : yymmdd10.;
format d_date date9.;
cards;
100001 ADVIL 2010-03-25
100001 TILENOL 2010-04-08
100001 TILENOL 2010-04-10
100001 TILENOL 2010-04-12
100001 TILENOL 2010-04-14
100001 TILENOL 2010-04-28
100001 TILENOL 2010-05-01
100002 ADVIL 2010-04-01
100002 ADVIL 2010-04-09
100002 ADVIL 2010-04-10
100002 ADVIL 2010-04-12
100002 ADVIL 2010-04-14
100002 TILENOL 2010-04-28
100002 TILENOL 2010-05-01
;run;



proc sql;
select unique id, drug
from
(
select
id,
drug,
d_date,
count(*) as cnt
from
(
select
a.*,
b.id as b_id,
b.drug as b_drug,
b.d_date as b_d_date
from pat a
join pat b on a.id=b.id
and a.drug=b.drug
and a.d_date between b.d_date-7 and b.d_date
) a
group by 1,2,3
having count(*)>=3
);
quit;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

New Learning Events in April

 

Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.

LEARN MORE

Discussion stats
  • 7 replies
  • 1332 views
  • 0 likes
  • 5 in conversation