BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
khalidamin
Obsidian | Level 7

Capture.PNG
Want to select patients who had ONLY surgery as ONLY treatment.

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

If I understand you correctly, this is what you want

 

data have;
input Pt $ malignancy Treatment $;
datalines;
A 1 Chemo
A 1 Surgery
A 1 Radio
A 2 Surgery
B 1 Surgery
C 1 Surgery
C 1 Chemo
D 1 Surgery
;

proc sql;
   create table want as
   select * from have 
   group by Pt, malignancy
   having sum(Treatment='Surgery')=n(Treatment);
quit;

Result:

 

Pt  malignancy  Treatment 
A   2           Surgery 
B   1           Surgery 
D   1           Surgery 

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Patient A has other treatments? Why is he in there?

PeterClemmensen
Tourmaline | Level 20

If I understand you correctly, this is what you want

 

data have;
input Pt $ malignancy Treatment $;
datalines;
A 1 Chemo
A 1 Surgery
A 1 Radio
A 2 Surgery
B 1 Surgery
C 1 Surgery
C 1 Chemo
D 1 Surgery
;

proc sql;
   create table want as
   select * from have 
   group by Pt, malignancy
   having sum(Treatment='Surgery')=n(Treatment);
quit;

Result:

 

Pt  malignancy  Treatment 
A   2           Surgery 
B   1           Surgery 
D   1           Surgery 
khalidamin
Obsidian | Level 7

Thank you so much! The solution worked perfectly, appreciate your help.

Pt A was there because that patient had only surgery for malignancy # 2. But, we can't select that patient for malignancy #1 because the patient had multiple treatments for malignancy 1..

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for 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
  • 3 replies
  • 819 views
  • 1 like
  • 2 in conversation