BookmarkSubscribeRSS Feed
Nikhil28
Fluorite | Level 6

HI,

 

I have a file with heaps of patients, their admission dates and re-admission dates. I want to calculate the % of re-admission within 3 months. If the patient has multiple re-admission then I want it to calculate from the first admission date.

 

How do I use or create a formula for it.

 

Data example -

 

Screen Shot 2018-09-23 at 3.05.30 pm.png

20 REPLIES 20
Jagadishkatam
Amethyst | Level 16
Could you please provide the data in the format that can be copied
Thanks,
Jag
Kurt_Bremser
Super User

Please post example data as data step code with datalines. Nobody likes having to type text from pictures, and not knowing the correct variable attributes makes finding the right solution even harder.

Also post an example for the expected result from that dataset.

Nikhil28
Fluorite | Level 6

Please see the attached file.

 

Would love to see the output something like -

 

OUTPUT        
EPISODE_IDADMISSION_NUMADMISSION_DATE_IDPAT_UR_NUMDISCHARGE_DATE_IDDAYSDRG_CODE_VER_042RE-ADMISSION COUNT IF WITHIN 3 MONTHS
28-1048401048402015-08-31    59332015-09-25                                                 25U66Z0 
28-106124  1061242015-09-29    59332015-10-22                                                 52U66Z1 
28-79790   797902014-04-03    67092014-05-0431U66Z1 
28-82421   824212014-05-16    67092014-05-1744U66Z1 
28-83433   834332014-06-05    67092014-06-1371U66Z1 

ID 

Kurt_Bremser
Super User

Please READ my post.

DATA.STEP.WITH.DATALINES.

Excel files are useless for representing SAS datasets. No types, defined lengths, formats. And many corporate sites block their download from the internet.

With the macro from my footnote, converting a SAS dataset to a data step is done in the same time you need for the export to Excel, and we get something we can use.

Nikhil28
Fluorite | Level 6
Unfortunately I only have the data set in excel for the time being - a new SAS user at the moment, apologies for my ignorance.
Nikhil28
Fluorite | Level 6
That is a small data set directly from SAS, just exported into excel. Thanks
Kurt_Bremser
Super User

Then use the macro from my footnotes to convert it to a data step, or write that step yourself. Preparing example or simulation data is an extremely useful SAS skill in itself.

Nikhil28
Fluorite | Level 6
Sorry couldn’t see the footnote to convert it into data step.
mkeintz
PROC Star

Help us help you.   If you can properly supply the data, then forum participants can  help develop a solution.  If you provide a picture of the data or a spreadsheet of the data, you are effectively outsourcing the proper creation of the topic, whereas the best forum convention is outsourcing only the solution. 

 

I'm surprised that you can't link to the "how to post code" url provided by @Kurt_Bremser's.  In short you would benefit by posting code and data that look like this:

 

data have;
  infile datalines dlm=',';
  input episode_??.   id ??   admission_num ??   pat_ur_num ??
          admission_date_id ??  discharge_date_id ??   days ??;
datalines;
28-104840, 104840, 5933, 2015-08-31, 2015-09-25, .
.....
28-123468,123468,7721,2017-01-06,2017-10-20,.
run;

You will need to (1) fill in the data where I inserted the ellipsis, and (2) fill in proper informats where I have inserted ??.   Then people can not only suggest solutions, but test their suggestions prior to responding.

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ChrisHemedinger
Community Manager

In the interest of moving things along, here's a DATA step with the data lines.  I generated this in EG by using the Import Data task, and then selected to include the records as data lines in the program.

 

/* --------------------------------------------------------------------
   Code generated by a SAS task
   -------------------------------------------------------------------- */

/* --------------------------------------------------------------------
   This DATA step reads the data values from DATALINES within the SAS
   code. The values within the DATALINES were extracted from the text
   source file by the Import Data wizard.
   -------------------------------------------------------------------- */

DATA WORK.READMIT;
    LENGTH
        EPISODE_ID       $ 9
        ADMISSION_NUM      8
        ADMISSION_DATE_ID   8
        PAT_UR_NUM         8
        DISCHARGE_DATE_ID   8
        DRG_CODE_VER_042 $ 4 ;
    FORMAT
        EPISODE_ID       $CHAR9.
        ADMISSION_NUM    BEST6.
        ADMISSION_DATE_ID DATE9.
        PAT_UR_NUM       BEST4.
        DISCHARGE_DATE_ID DATE9.
        DRG_CODE_VER_042 $CHAR4. ;
    INFORMAT
        EPISODE_ID       $CHAR9.
        ADMISSION_NUM    BEST6.
        ADMISSION_DATE_ID DATE9.
        PAT_UR_NUM       BEST4.
        DISCHARGE_DATE_ID DATE9.
        DRG_CODE_VER_042 $CHAR4. ;
    INFILE DATALINES4
        DLM=','
        MISSOVER
        DSD ;
    INPUT
        EPISODE_ID       : $CHAR9.
        ADMISSION_NUM    : ?? BEST6.
        ADMISSION_DATE_ID : ?? DATE9.
        PAT_UR_NUM       : ?? BEST4.
        DISCHARGE_DATE_ID : ?? DATE9.
        DRG_CODE_VER_042 : $CHAR4. ;
DATALINES4;
28-60030,60030,15FEB2013,124,08MAR2013,U66Z
28-142929,142929,04JUL2018,1442,20AUG2018,U66Z
28-124021,124021,30JAN2017,5650,16MAR2017,U66Z
28-104840,104840,31AUG2015,5933,25SEP2015,U66Z
28-106124,106124,29SEP2015,5933,22OCT2015,U66Z
28-129352,129352,16JUN2017,6068,21AUG2017,U66Z
28-57751,57751,10JAN2013,6170,31JAN2013,U66Z
28-66130,66130,13JUN2013,6184,28JUN2013,U66Z
28-59972,59972,14FEB2013,6349,18MAR2013,U66Z
28-61234,61234,07MAR2013,6385,20MAR2013,U66Z
28-63178,63178,12APR2013,6427,13APR2013,U66Z
11-488117,488117,11NOV2017,6527,09DEC2017,U66Z
11-515347,515347,29MAY2018,6527,22JUN2018,U66Z
28-68397,68397,05AUG2013,6557,16AUG2013,U66Z
28-110635,110635,22JAN2016,6648,09FEB2016,U66Z
28-79790,79790,03APR2014,6709,04MAY2014,U66Z
28-82421,82421,16MAY2014,6709,17MAY2014,U66Z
28-83433,83433,05JUN2014,6709,13JUN2014,U66Z
28-85484,85484,08JUL2014,6709,20AUG2014,U66Z
28-88149,88149,29AUG2014,6709,12SEP2014,U66Z
28-72646,72646,13NOV2013,6732,22NOV2013,U66Z
28-73012,73012,20NOV2013,6750,19DEC2013,U66Z
28-73191,73191,21NOV2013,6753,25NOV2013,U66Z
;;;;

Become an Explorer! Join SAS Analytics Explorers to learn and complete challenges that earn rewards!

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand in the Innovate Hub.

Watch Now →
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 20 replies
  • 15628 views
  • 7 likes
  • 5 in conversation