Help using Base SAS procedures

something similar to PROC FREQ???

Reply
Occasional Contributor
Posts: 16

something similar to PROC FREQ???

I want to do something similar to proc freq, I have the following data set that shows the type of treatment the patient was prescribed and the date of prescription. I managed to sort by prescription:

subject treatment prescribed_date
1 A 08/08/1997
1 B 07/09/2000
1 A 05/06/2002
2 A 08/03/1996
2 B 12/01/1999
2 A 05/06/2002
2 B 09/11/2003
3 B 02/05/1992
4 B 02/08/1998
5 A 05 /09/1999
6 A 06 /06/2000
7 A 08/08/1997
7 B 07/09/2000
7 A 05/06/2002

Is it possible to request SAS to perform the following: Tell me how many patients the received the treatments in the order ABA, ABAB, etc.

That is I will like SAS to tell me or produce a table showing me that there are 2 patients who received the treatments in the order ABA, 1 patient in the order ABAB, 2 patients in the order B only. 2 patients in order A

Please help
Super User
Posts: 5,254

Re: something similar to PROC FREQ???

There is no standard way of doing this that I aware of.
You'll probably en up with using the data step together with RETAIN.
One way is to build up a string (ABA, ABAB etc) for each patient, and then doing a PROC FREQ on the result.
/Linus
Data never sleeps
SAS Employee
Posts: 160

Re: something similar to PROC FREQ???

[pre]data input;
input subject treatment $ prescribed_date ddmmyy10.;
datalines;
1 A 08/08/1997
1 B 07/09/2000
1 A 05/06/2002
2 A 08/03/1996
2 B 12/01/1999
2 A 05/06/2002
2 B 09/11/2003
3 B 02/05/1992
4 B 02/08/1998
5 A 05/09/1999
6 A 06/06/2000
7 A 08/08/1997
7 B 07/09/2000
7 A 05/06/2002
;
run;

proc sort data=input;
by subject prescribed_date treatment;
run;

proc transpose data=input
out=trans;
by subject;
var treatment;
run;

data treatments;
set trans;
treatments=cats(of colSmiley Happy;
run;

proc freq data=treatments;
tables treatments /list;
run;
Ask a Question
Discussion stats
  • 2 replies
  • 105 views
  • 0 likes
  • 3 in conversation