Count of atleast one event for particular Subject

Reply
Frequent Contributor
Posts: 89

Count of atleast one event for particular Subject

Hai All.

This is my data set(Table 1).I need  to get the output from this table(Table 1)

Table 1

SubjectTreatmentevent
Usubjid_01XA
Usubjid_02XA1
Usubjid_03XB
Usubjid_03XC
Usubjid_04XA2
Usubjid_05XA3

           I would like to get below table(table 2)(Based on subject how many test is assigned for particular treatment) .I need to get the count of each event in each column(subject for 1 event etc.)

1 event

Table 2

TreatmentN
total event
subject for 1 eventsubject for 2 eventsubject for >=3 event
A56420

N= total no of distinct subject

total event = total no of distinct event

Subject for 1 event (count of at least one event under  treatment)

Subject for 2 event (count of at least two event under  treatment)

Subject for 3 event (count of at least >=3 event under  treatment)

Thanks

Krishna

Message was edited by: Krishna chandran

Super User
Posts: 19,157

Re: Count of atleast one event for particular Subject

Krishna chandran wrote:

  I have  a doubt in my data step programming.

Did you mean to include your program?

Frequent Contributor
Posts: 89

Re: Count of atleast one event for particular Subject

Hai Reeza

       Sorry for making inconvenience .. Am not able to include my program.That why i show the sample skeleton of my table.

Super User
Posts: 19,157

Re: Count of atleast one event for particular Subject

Why can't you include your code? There shouldn't be anything confidential in your code.

I'm not following your example to be honest, so I don't know what your output should look like. Can you fill in the boxes to help explain the logic?

Super User
Posts: 9,873

Re: Count of atleast one event for particular Subject

You need to post what output you need according to your sample data .


data have;
input subject : $20. treatment $ event $ ;
cards;
Usubjid_01     A     X
Usubjid_01     A     Y
Usubjid_01     B     X
Usubjid_02     B     Y
Usubjid_02     B     Z
Usubjid_03     A     X
Usubjid_03     B     Y
;
run;
proc sql;
 create table want as
  select treatment,sum(n=1) as Subject_for_1_event,sum(n=2) as Subject_for_2_event,sum(n=3) as Subject_for_3_event
   from (select treatment,subject,count(*) as n from have group by treatment,subject)
    group by treatment;
quit;

Xia Keshan

Frequent Contributor
Posts: 89

Re: Count of atleast one event for particular Subject

Hai xia

   sorry for making delay..I was suffering fever.

I updated the sample table. Please help to find the solution

thanks

krishna

Ask a Question
Discussion stats
  • 5 replies
  • 218 views
  • 0 likes
  • 3 in conversation