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-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
  • 6 replies
  • 870 views
  • 0 likes
  • 3 in conversation