(Note: this is a homework assignment for which I have the correct answer, but I am unsatisfied with the results.)
A little context with regards to the data. Information on each of four drugs was recorded for a patient's coming in for a clinic visit: a code of 0 indicates the drug is not being taken, a code of 1 indicates the drug is being started, a code of 2 indicates that drug is being discontinued. For each visit, a patient ID, visit date, and the status codes of the four drugs are recorded.
My goal is to only use PROC SORT
and DATA _NULL_
procedures to produce a report. I have had success using a PUT
statement in the DATA _NULL_
step to create a list of individuals who have used all prescription drugs, but how would I go about producing a report showing the total number of individuals who have used all prescription drugs?
Current Output
Patient 01 has taken 4 different drugs
Patient 03 has taken 4 different drugs
Patient 04 has taken 4 different drugs
Desired Output
There are 3 patients who have taken 4 different drugs.
Code
DATA drug;
Input ID : $2. Visit : MMDDYY8. rx_1-rx_4;
Datalines;
04 01/28/95 1 0 1 1
03 02/28/95 2 0 2 1
05 05/20/95 0 0 0 0
01 03/27/95 1 0 0 1
03 03/02/95 0 0 0 1
01 04/04/95 0 1 1 1
02 04/29/95 0 1 1 1
02 05/04/95 0 0 1 0
03 02/26/95 1 0 1 1
03 03/06/95 0 1 0 1
04 01/25/95 0 0 1 0
05 03/01/95 0 0 0 0
02 04/30/95 0 2 1 2
01 03/31/95 2 1 0 1
03 03/07/95 0 1 0 2
04 02/01/95 1 1 1 1
05 04/18/95 0 0 0 0
01 04/09/95 0 2 1 2
;
PROC SORT Data = Drug;
By id visit;
RUN;
%let num_rx_var = %eval(4);
DATA _null_;
File Print;
Set drug;
By id;
Array
rx_indicator{&num_rx_var} rx_1-rx_4;
Array
takes_rx_{&num_rx_var} (&num_rx_var*0);
Array
has_taken_rx_{&num_rx_var} (&num_rx_var*0);
Do i=1 To &num_rx_var;
takes_rx_{i} = 0;
End;
Do i=1 To &num_rx_var;
takes_rx_{i} = takes_rx_{i} or (rx_indicator{i}>0);
sum_dif_rx_visit = sum(of takes_rx_{*});
End;
If first.id Then
Do i=1 To &num_rx_var;
has_taken_rx_{i} = 0;
End;
Do i=1 To &num_rx_var;
has_taken_rx_{i} = has_taken_rx_{i} or (rx_indicator{i}>0);
End;
If last.id Then Do;
num_diff_rx = sum(of has_taken_rx_{*});
End;
all_drugs = count(num_diff_rx, &num_rx_var);
If all_drugs = 1 Then Put "Patient " id "has taken " num_diff_rx "different drugs" ;
RUN;