BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
elvics
Calcite | Level 5

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
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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

3 REPLIES 3
ballardw
Super User

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

Ksharp
Super User

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;

elvics
Calcite | Level 5

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;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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