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 |
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;
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;
it always helps to have that second pair of eyes! Yes, spelling correction fixed the problem.
Thank you!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.