BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
HDSimo
Calcite | Level 5

Hi,

this is an ipotetic DS

data x;

input a b;

cards;

5 1

6 2

2 4

5 3

6 1

4 2

8 3

9 2

;run;

Is it possible with only one proc SQL calculate count of a and count of a where b=1?

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

I, too, am not sure what you want.  The way I interpreted your question I think you are looking for something like:

proc sql;

  select (select count(a)

    from x

      where b eq 1 ) as part_a,

        count(a) as all_a

         from x

  ;

quit;

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

Not sure what you want exactly, but perhaps using SUM will work.

proc sql noprint ;

   create table counts as

    select distinct A,count(*) as count,sum(b=1) as countb1

     from x

     group by a

   ;

quit;

Obs    a    count    countb1

1     2      1         0

2     4      1         0

3     5      2         1

4     6      2         1

5     8      1         0

6     9      1         0

art297
Opal | Level 21

I, too, am not sure what you want.  The way I interpreted your question I think you are looking for something like:

proc sql;

  select (select count(a)

    from x

      where b eq 1 ) as part_a,

        count(a) as all_a

         from x

  ;

quit;

HDSimo
Calcite | Level 5

Thank you Art297. It works!

Ksharp
Super User
data x;
input a b;
cards;
5 1
6 2
2 4
5 3
6 1
4 2
8 3
9 2
;run;
proc sql;
 select count(*) as count_a,
  sum(case when(b=1) then 1 else 0 end) as part_a
  from x;
quit;

Ksharp

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 4 replies
  • 966 views
  • 0 likes
  • 4 in conversation