DATA Step, Macro, Functions and more

help sum calculation by patient id

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 142
Accepted Solution

help sum calculation by patient id

[ Edited ]

Hi! I need some help troubleshooting this syntax.  Basically, I want to count all 'Oral Steroid' prescription fills by patientid.  if there is an steroid use (i.e. gt 0) then variable Controlled='No', else 'Yes' .

 

The output I am getting is not suming steroids (i.e. tot_steroids) by patient id.  I is giving me a running total down all observations...and summing something untrelated to steroid use...but not sure what is it summing, and it is outputting TWO varialbes for 'tot_steroid'??  Help is appreciated!

 


data mtf.control_status;
set mtf.ipop_mtf_pdts (rename=(G=Drug_type));
by patientid;
    if first.patientid then do;
    steroid=0;
    tot_steriod=0; *initiate back to zero with each new patient id;
end;
    if drug_type='Oral Steroids' then steroid=1;
        else steroid=0;
tot_steroid + steroid; *summing oral steroid pharmacy data;
    if  tot_steroid gt 0 then Controlled='No'; *at some point this patient used oral steroids;
        else Controlled='Yes';
    if last.patientid then output; *the last patientid with summed pharmacy claims;
run;

 

 

Output looks like this (by patientid)

SAS Output

Obs Drug_type steroid tot_steroid Controlled
1 Rescue 0 3 No
2 Control 0 3 No
3 Control 0 3 No
4 Rescue 0 3 No
5 Control 0 3 No
6   0 3 No
7 Control 0 3 No
8 Control 0 21 No
9 Rescue 0 21 No
10 Oral Steroids 1 28 No
11 Rescue 0 28 No
12 Rescue 0 28 No
13 Rescue 0 28 No
14 Rescue 0 28 No
15 Control 0 28 No

Accepted Solutions
Solution
‎06-14-2016 03:36 PM
Super User
Posts: 11,343

Re: help sum calculation by patient id

Some actual data input data in the form of a datastep would help to test actual code.

 

But your error is spelling in this line:

 tot_steriod=0;

I think you meant

 

tot_steroid=0;

View solution in original post


All Replies
Solution
‎06-14-2016 03:36 PM
Super User
Posts: 11,343

Re: help sum calculation by patient id

Some actual data input data in the form of a datastep would help to test actual code.

 

But your error is spelling in this line:

 tot_steriod=0;

I think you meant

 

tot_steroid=0;

Frequent Contributor
Posts: 142

Re: help sum calculation by patient id

it always helps to have that second pair of eyes!  Yes, spelling correction fixed the problem.

 

Thank you!

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 221 views
  • 0 likes
  • 2 in conversation