input score ts$ tc$ matching;
180 A B 0
200 B B 1
360 A B 0
420 A A 1
500 B A 0
234 B B 1
461 B A 0
if ts='A' and tc='B' then group='1';
if ts='B' and tc='B' then group='2';
if ts='B' and tc='A' then group='3';
if ts='A' and tc='A' then group='4';
proc sgplot data=want;
I don't think the problem is formulated correctly. To get two overlayed histograms, you need some observations that belong to one group and other (disjoint) observations in another group. But in your example, ts='A' includes observations for both tc='A' and tc='B'. So you can't overlay the histograms. There are not four histograms to overlay.
Two things that you can do:
1. create two overlapping histograms. The first compares tc='A' and tc='B' given that ts='A'. The second compares tc='A' and tc='B' given that ts='B'.
2. create a panel of histograms of the four groups, which are the joint levels of (ts, tc).
Both of these options are shown below on some simulated data:
do ts = 'A', 'B';
do tc = 'A', 'B';
do k=1 to 50;
score = 3*(ts='A') + -1*(tc='A') + rand("Normal");
/* 1. Given a value for ts, overlay the distributions for levels of tc */
proc sgplot data=Have;
histogram score / group=tc transparency=0.5;
/* 2. Panel the four distributions */
group = cats("ts=", ts, "; tc=", tc);
proc sgpanel data=Want;
panelby group / onepanel columns=1 novarname;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.