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-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!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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