BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jay_bhavsar
Obsidian | Level 7
Data have
Result PID treatment
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
Result want count
T R O
2 1 3

Thanka in advance
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Try this

 

proc sql;
   create table want as
   select treatment,
          count(distinct PID) as count
   from have
   where Result = 'Yes'
   group by treatment;
quit;

View solution in original post

6 REPLIES 6
PhilC
Rhodochrosite | Level 12

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.

PeterClemmensen
Tourmaline | Level 20

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;
jay_bhavsar
Obsidian | Level 7
Dear PeterClemmensen,
Thanks for your answer. your SQL giving me the result, but one more thing i want to add the i only want to consider yes from result variable. so i added onw more patient. Then how to calculate the count?
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
No 4 R
No 4 R
;
PeterClemmensen
Tourmaline | Level 20

Try this

 

proc sql;
   create table want as
   select treatment,
          count(distinct PID) as count
   from have
   where Result = 'Yes'
   group by treatment;
quit;
jay_bhavsar
Obsidian | Level 7
It worked...
I learned new thing today. Thank you so much for your support.
ballardw
Super User

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.

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 1166 views
  • 2 likes
  • 4 in conversation