BookmarkSubscribeRSS Feed
Statsconsultancy
Fluorite | Level 6
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
2 REPLIES 2
LinusH
Tourmaline | Level 20
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
GertNissen
Barite | Level 11
[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 col:);
run;

proc freq data=treatments;
tables treatments /list;
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1449 views
  • 0 likes
  • 3 in conversation