Try this
proc sql;
create table want as
select treatment,
count(distinct PID) as count
from have
where Result = 'Yes'
group by treatment;
quit;
WIll this help:
Your data ain't good looking, but it has a nice cardinality - The SAS Dummy
@ChrisHemedinger, I still laugh at the song lyrics in this article.
There you go.
Transpose if you want
data have;
input Result $ PID treatment $;
datalines;
Yes 1 T
No 1 T
Yes 1 T
Yes 1 O
No 2 R
Yes 2 R
Yes 2 O
Yes 3 T
Yes 3 T
Yes 3 T
Yes 3 O
;
proc sql;
create table want as
select treatment,
count(distinct PID) as count
from have
group by treatment;
quit;
Try this
proc sql;
create table want as
select treatment,
count(distinct PID) as count
from have
where Result = 'Yes'
group by treatment;
quit;
Do you want a data set for manipulation or a report people read?
If you don't mind a vertical report the Nlevels option in Proc Freq may suit.
Example:
proc freq data=sashelp.class nlevels;
ods output nlevels=work.levels;
ods select nlevels;
run;
Which if you have MISSING values will also have a summary involving those n the work.nlevels data set created. If you don't like the vertical layout you could transpose the work.levels, or write a report to use the work.levels.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.