BookmarkSubscribeRSS Feed
antoniodneto
Calcite | Level 5

Hi guys,

I have one table with many where clauses. I need to count a number of cases for each where clause.

 

For example:

apply filter 1 how many cases was filtered, then I apply filter 2 and count the cases again.

 

Thank you guys!!

7 REPLIES 7
Shmuel
Garnet | Level 18

Am I right, you want to count number of observations (cases) per different conditions (where clause).

You can do it in one step using IF statements:

data want;
  set have(end=eof);
      retain count1 count2 ...;
      if <condition-1> then count1+1;
      if <condition-2> then count2+1;
     ....
     if eof then do;
       output;  /* save result in a data set */
       put count1= count2= ...;  /* print result in log */
    end;
    keep count1 count2 ...;
run;

antoniodneto
Calcite | Level 5

Hi Shmuel,

Can I do it into a PROC SQL statement, because I have some joins inside.

 

Tks

Shmuel
Garnet | Level 18

Please post:

1) a test data of your table

2) a pseudo code to show what you mean by join and some typical conditions

3) relating to test data - show required results

antoniodneto
Calcite | Level 5

PROC SQL;
CREATE TABLE TESTE AS
SELECT DISTINCT T1.*
FROM TESTE_2 T1

INNER JOIN TESTE_3 T2 ON T1.NAME = T2.NAME
INNER JOIN TESTE_4 T3 ON T1.NAME = T3.NAME
LEFT JOIN TESTE_5 t4 ON T1.NAME = T4.NAME
LEFT JOIN TESTE_6 T5 ON T1.NAME = T5.NAME

WHERE

T3.NAME IS MISSING AND
T4.NAME IS MISSING AND
T5.NAME IS MISSING

;
RUN;

 

 

That is my sample, So I need to count the cases for each filter:

Apply T3.NAME IS MISSING (count how many cases out for this filter) then apply the second (count again)....

 

It helps?

Thank you so much!

Kurt_Bremser
Super User

You cannot count the discrete missing conditions from the joined table (because of the "AND").

You need to get the counts separately for each joined table.

Hint: because of the inner join, t3.name can only be missing if t1.name is missing.

antoniodneto
Calcite | Level 5

Hi @Shmuel,

Can you still help me?

 

Tks!!!

Shmuel
Garnet | Level 18

Try do it  with 2 steps:

1) use sql to create the joins, without any where clause for counting

2) use the data step I posted as example

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 868 views
  • 0 likes
  • 3 in conversation