BookmarkSubscribeRSS Feed
tmm
Fluorite | Level 6 tmm
Fluorite | Level 6

I have a table that has the following:

comparison              admission                       count

1111                         noreadmit                          0

1111                         readmit                             0

2222                         noreadmit                        12

2222                         readmit                            1

3333                        noreadmit                         12

3333                        readmit                             4

I want to return all the above data but only if there is a sum between readmit and noreadmit >=10 but I need it to also return the readmit associated. This is the code I used but it does not return correctly.

/*********************************GRAB ONLY THOSE TINS THAT HAD A READMIT**************************/

/*********************************FOR CHI ALONG WITH NATIONAL OVERALL****************************/

PROC SQL;

CREATE TABLE ReAdm.CHI2 AS

SELECT *

FROM ReAdm.CHI

GROUP BY COMPARISON

HAVING SUM(UPCASE(ADMISSION)='NOREADMIT' AND COUNT>=10)=0;

RUN;

6 REPLIES 6
FloydNevseta
Pyrite | Level 9

proc sql;

create table want as

select

   a.*

from

   have     a

   join

   ( select comparison

      from have

      group by comparison

      having sum( count ) >= 10 )   b

      on

      a.comparison = b.comparison

where

   a.admission = 'readmit'

;

quit;

tmm
Fluorite | Level 6 tmm
Fluorite | Level 6

And this will keep the readmit and noreadmit part of the admission column?

tmm
Fluorite | Level 6 tmm
Fluorite | Level 6

That does not return the right results. The old code that worked for the readmit side was this:

PROC SQL;

CREATE TABLE ReAdm.CHI2 AS

SELECT *

FROM ReAdm.CHI

GROUP BY COMPARISON

HAVING SUM(UPCASE(ADMISSION)='READMIT' AND COUNT=0)=0;

RUN;

But now the goal is to return the readmit and noreadmits where the sum of the readmit and noreadmits has a count of >=10

Linlin
Lapis Lazuli | Level 10

what is your wanted output from your sample data?

tmm
Fluorite | Level 6 tmm
Fluorite | Level 6

Nevermind. I was able to take a previous table I created that summed my noreadmits and readmits and give me a totaladmission column and I just created a SAS query off that which says give me the totaladmissions >=10 but leave rest of the columns for me.

FloydNevseta
Pyrite | Level 9

Your initial post said you wanted only the readmits. if now you want both, then remove the where clause.


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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 1141 views
  • 0 likes
  • 3 in conversation