Help using Base SAS procedures

Calculation for days of drug usage for one year, but not exceed 120 days between two prescription

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Calculation for days of drug usage for one year, but not exceed 120 days between two prescription

Dear all,

 

I want to calculate the regular use of drug. The defination is that regular users was the regular use of drug for "more than a year" and "the interval between successive prescription drug records cannot exceed 120 days".

 

I wish the the data was presented as "Category (Correct)".

When the date between two prescriptions were within 120 days (Dif_Days), they belonged the same group.

If the date long than 120 days (Dif_Days), the next prescriptions was categorized as new group.

 

At one of steps, I cannot run the the correct category. How cou;d I modify the syntax?

 

DATA Final;
SET data;
by ID Drug_start
if first.ID then Category=1;
if Dif_Days<=120 then Category=1;
else Category+1;
run;

 

The data was shown as below.

 

Drug_start: the first date for this prescription

Drug_end:  the end date for this prescription

Drug_day: how long for this prescription

 

Dif_Days: the difference between the Drug_start and last Drug_end

 

IDDrug_startDrug_endDrug_dayDif_DaysCategoryCategory (Correct)
AAA200910112009110930 11
AAA200911092009120830011
AAA20110317201104153046422
AAA2011052320110621303812
AAA2011081020110908305012
AAA201109092011100830112
AAA201110052011110330-312
AAA20130217201303183047223
AAA201303132013041130-513
BBB    11
BBB    11
CCC200806052008061814 11
CCC2010031120100317763122
CCC201003182010033114112
CCC20110616201107132844223
CCC20111124201112212813434
CCC20121115201212122833045
CCC201212072013010328-515
CCC201301102013020628715
CCC2013041820130515287115
CCC2013053020130626281515
CCC2013070620130802281015
CCC201307272013082328-615

Accepted Solutions
Solution
‎10-22-2016 03:12 AM
Super User
Posts: 9,691

Re: Calculation for days of drug usage for one year, but not exceed 120 days between two prescriptio

[ Edited ]

I don't understand.

CODE NOT TEST.

 

DATA Final;
SET data;
by ID ;
if first.ID then Category=0;
if Dif_Days>120 or first.ID then Category+1;
run;

View solution in original post


All Replies
Super User
Posts: 10,538

Re: Calculation for days of drug usage for one year, but not exceed 120 days between two prescriptio

First thing: Are your date variables SAS date valued and currently assigned a format of yymmdd8., character or numeric as shown? If they are not SAS you will want to create SAS date values. The approach differs depending on the variable type of your current values.

 

Then the value of Dif_days can be calculated in a datasetp as:

 

Dif_days = SASstartdate - lag(SASenddate);  (or do the conversion on the fly with the Lag value of date_end)

You will want to NOT calculate the dif_days this way for the first.ID

Solution
‎10-22-2016 03:12 AM
Super User
Posts: 9,691

Re: Calculation for days of drug usage for one year, but not exceed 120 days between two prescriptio

[ Edited ]

I don't understand.

CODE NOT TEST.

 

DATA Final;
SET data;
by ID ;
if first.ID then Category=0;
if Dif_Days>120 or first.ID then Category+1;
run;

New Contributor
Posts: 2

Re: Calculation for days of drug usage for one year, but not exceed 120 days between two prescriptio

Thanks at lot.

It works.

But it seems need to be sort by ID and Drug_start.

DATA Final;
SET data;
by ID Drug_start;
if first.ID then Category=0;
if Dif_Days>120 or first.ID then Category+1;
run;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 233 views
  • 0 likes
  • 3 in conversation