Sunday, 23 November 2025

318.HOSPITAL SERVICE QUALITY ANALYSIS DATASET CREATION WITH DATE DERIVATIONS | SERVICE SCORE AUTOMATION USING MACROS | PROC SQL | PROC MEANS | PROC CORR | PROC FORMAT | PROC SGPLOT

HOSPITAL SERVICE QUALITY ANALYSIS DATASET CREATION WITH DATE DERIVATIONS | SERVICE SCORE AUTOMATION USING MACROS | PROC SQL | PROC MEANS | PROC CORR | PROC FORMAT | PROC SGPLOT

 options nocenter;

1. CREATE HOSPITAL SERVICE QUALITY DATASET USING PROC SQL

proc sql;

  create table work.hospital_raw as

  select 

    "CityCare General"  as Hospital_Name length=30,

    "Hyderabad"          as City length=20,

    250                  as Bed_Count,

    80                   as Doctor_Count,

    45                   as Avg_Wait_Time,

    2.1                  as Mortality_Rate,

    88                   as Patient_Satisfaction,

    '15JAN2018'd         as Accreditation_Date,

    '10OCT2024'd         as Survey_Date

  from sashelp.class(obs=1)

  union all

  select 

    "Sunrise Multispecialty",

    "Bengaluru",

    320,

    120,

    30,

    1.5,

    92,

    '01JUL2016'd,

    '20SEP2024'd

  from sashelp.class(obs=1)

  union all

  select 

    "GreenLeaf Hospital",

    "Chennai",

    180,

    60,

    55,

    2.8,

    81,

    '10MAR2019'd,

    '05AUG2024'd

  from sashelp.class(obs=1)

  union all

  select 

    "RiverView Medical",

    "Mumbai",

    400,

    150,

    35,

    1.9,

    90,

    '22NOV2015'd,

    '12NOV2024'd

  from sashelp.class(obs=1)

  union all

  select 

    "Lotus Heart Institute",

    "Pune",

    220,

    90,

    40,

    2.3,

    86,

    '05MAY2017'd,

    '28OCT2024'd

  from sashelp.class(obs=1)

  union all

  select 

    "MetroLife Care",

    "Delhi",

    520,

    210,

    50,

    2.6,

    79,

    '18DEC2014'd,

    '15SEP2024'd

  from sashelp.class(obs=1)

  union all

  select 

    "Harmony Health Center",

    "Kolkata",

    260,

    100,

    42,

    2.0,

    84,

    '09APR2018'd,

    '08OCT2024'd

  from sashelp.class(obs=1)

  union all

  select 

    "SilverLine Hospital",

    "Hyderabad",

    150,

    55,

    38,

    1.7,

    89,

    '01JAN2020'd,

    '25AUG2024'd

  from sashelp.class(obs=1)

  union all

  select 

    "Skyline Supercare",

    "Bengaluru",

    300,

    110,

    33,

    1.6,

    91,

    '11FEB2016'd,

    '05NOV2024'd

  from sashelp.class(obs=1)

  union all

  select 

    "Coastal Life Hospital",

    "Visakhapatnam",

    190,

    70,

    47,

    2.4,

    83,

    '20SEP2019'd,

    '30SEP2024'd

  from sashelp.class(obs=1)

  union all

  select 

    "TruHealth Specialty",

    "Chennai",

    210,

    85,

    52,

    2.9,

    77,

    '14AUG2017'd,

    '18OCT2024'd

  from sashelp.class(obs=1)

  union all

  select 

    "EverCare Clinic",

    "Mumbai",

    130,

    45,

    28,

    1.3,

    94,

    '02FEB2021'd,

    '01NOV2024'd

  from sashelp.class(obs=1)

  ;

quit;

proc print data=work.hospital_raw;

run;

OUTPUT:

ObsHospital_NameCityBed_CountDoctor_CountAvg_Wait_TimeMortality_RatePatient_SatisfactionAccreditation_DateSurvey_Date
1CityCare GeneralHyderabad25080452.1882119923659
2Sunrise MultispecialtyBengaluru320120301.5922063623639
3GreenLeaf HospitalChennai18060552.8812161823593
4RiverView MedicalMumbai400150351.9902041423692
5Lotus Heart InstitutePune22090402.3862094423677
6MetroLife CareDelhi520210502.6792007523634
7Harmony Health CenterKolkata260100422.0842128323657
8SilverLine HospitalHyderabad15055381.7892191523613
9Skyline SupercareBengaluru300110331.6912049523685
10Coastal Life HospitalVisakhapatnam19070472.4832181223649
11TruHealth SpecialtyChennai21085522.9772104523667
12EverCare ClinicMumbai13045281.3942231323681


2. ADD DATE-BASED DERIVED VARIABLES (INTCK, INTNX)

data work.hospital_final;

  set work.hospital_raw;

  /* Format the date variables for readability */

  format Accreditation_Date Survey_Date Next_Survey_Due date9.;


  /* Years since accreditation using INTCK */

  Years_Since_Accred = intck('year', Accreditation_Date, Survey_Date, 'c');


  /* Next survey due exactly 1 year after current survey using INTNX */

  Next_Survey_Due    = intnx('year', Survey_Date, 1, 'same');


  /* Days between accreditation and latest survey */

  Days_Since_Accred  = intck('day', Accreditation_Date, Survey_Date);

run;

proc print data=work.hospital_final;

run;

OUTPUT:

ObsHospital_NameCityBed_CountDoctor_CountAvg_Wait_TimeMortality_RatePatient_SatisfactionAccreditation_DateSurvey_DateNext_Survey_DueYears_Since_AccredDays_Since_Accred
1CityCare GeneralHyderabad25080452.18815JAN201810OCT202410OCT202562460
2Sunrise MultispecialtyBengaluru320120301.59201JUL201620SEP202420SEP202583003
3GreenLeaf HospitalChennai18060552.88110MAR201905AUG202405AUG202551975
4RiverView MedicalMumbai400150351.99022NOV201512NOV202412NOV202583278
5Lotus Heart InstitutePune22090402.38605MAY201728OCT202428OCT202572733
6MetroLife CareDelhi520210502.67918DEC201415SEP202415SEP202593559
7Harmony Health CenterKolkata260100422.08409APR201808OCT202408OCT202562374
8SilverLine HospitalHyderabad15055381.78901JAN202025AUG202425AUG202541698
9Skyline SupercareBengaluru300110331.69111FEB201605NOV202405NOV202583190
10Coastal Life HospitalVisakhapatnam19070472.48320SEP201930SEP202430SEP202551837
11TruHealth SpecialtyChennai21085522.97714AUG201718OCT202418OCT202572622
12EverCare ClinicMumbai13045281.39402FEB202101NOV202401NOV202531368


3. DEFINE FORMATS FOR REPORTING USING PROC FORMAT

proc format;

  /* Patient satisfaction categories */

  value satsf

    0 - 69  = 'Low'

    70 - 84 = 'Medium'

    85 - 100= 'High';

LOG:

NOTE: Format SATSF has been output.

  /* Simple bed-count category */

  value bedcat

    0   - 199 = 'Small'

    200 - 349 = 'Medium'

    350 - high= 'Large';

run;

LOG:

NOTE: Format BEDCAT has been output.

4. MACRO FOR SERVICE-SCORE AUTOMATION

%macro calc_service_score(indata=, outdata=, 

                          w_wait=0.30, 

                          w_mort=0.30, 

                          w_satisf=0.40);


  data &outdata;

    set &indata;

    /* Assume realistic OPD waits < 100 minutes: lower wait is better */

    Wait_Score = 100 - Avg_Wait_Time;   


    /* Mortality rate assumed between 0 and 10%; penalise higher values */

    Mort_Score = 100 - (Mortality_Rate * 10);


    /* Patient satisfaction already a 0–100 type metric */

    Sat_Score  = Patient_Satisfaction;


    /* Weighted composite service score */

    Service_Score = (&w_wait  * Wait_Score) +

                    (&w_mort  * Mort_Score) +

                    (&w_satisf* Sat_Score);


    format Service_Score 6.2 Patient_Satisfaction satsf. Bed_Count bedcat.;

  run;

  proc print data=&outdata;

  run;

%mend calc_service_score;


%calc_service_score(indata=work.hospital_final,

                    outdata=work.hospital_scored,

                    w_wait=0.30,

                    w_mort=0.30,

                    w_satisf=0.40);

OUTPUT:

ObsHospital_NameCityBed_CountDoctor_CountAvg_Wait_TimeMortality_RatePatient_SatisfactionAccreditation_DateSurvey_DateNext_Survey_DueYears_Since_AccredDays_Since_AccredWait_ScoreMort_ScoreSat_ScoreService_Score
1CityCare GeneralHyderabadMedium80452.1High15JAN201810OCT202410OCT20256246055798875.40
2Sunrise MultispecialtyBengaluruMedium120301.5High01JUL201620SEP202420SEP20258300370859283.30
3GreenLeaf HospitalChennaiSmall60552.8Medium10MAR201905AUG202405AUG20255197545728167.50
4RiverView MedicalMumbaiLarge150351.9High22NOV201512NOV202412NOV20258327865819079.80
5Lotus Heart InstitutePuneMedium90402.3High05MAY201728OCT202428OCT20257273360778675.50
6MetroLife CareDelhiLarge210502.6Medium18DEC201415SEP202415SEP20259355950747968.80
7Harmony Health CenterKolkataMedium100422.0Medium09APR201808OCT202408OCT20256237458808475.00
8SilverLine HospitalHyderabadSmall55381.7High01JAN202025AUG202425AUG20254169862838979.10
9Skyline SupercareBengaluruMedium110331.6High11FEB201605NOV202405NOV20258319067849181.70
10Coastal Life HospitalVisakhapatnamSmall70472.4Medium20SEP201930SEP202430SEP20255183753768371.90
11TruHealth SpecialtyChennaiMedium85522.9Medium14AUG201718OCT202418OCT20257262248717766.50
12EverCare ClinicMumbaiSmall45281.3High02FEB202101NOV202401NOV20253136872879485.30


5. DESCRIPTIVE STATISTICS USING PROC MEANS

proc means data=work.hospital_scored

           n mean std min max maxdec=2;

  class City;

  var Bed_Count Doctor_Count Avg_Wait_Time Mortality_Rate 

      Patient_Satisfaction Service_Score Years_Since_Accred;

run;

OUTPUT:

The MEANS Procedure

CityN ObsVariableNMeanStd DevMinimumMaximum
Bengaluru2
Bed_Count
Doctor_Count
Avg_Wait_Time
Mortality_Rate
Patient_Satisfaction
Service_Score
Years_Since_Accred
2
2
2
2
2
2
2
310.00
115.00
31.50
1.55
91.50
82.50
8.00
14.14
7.07
2.12
0.07
0.71
1.13
0.00
300.00
110.00
30.00
1.50
91.00
81.70
8.00
320.00
120.00
33.00
1.60
92.00
83.30
8.00
Chennai2
Bed_Count
Doctor_Count
Avg_Wait_Time
Mortality_Rate
Patient_Satisfaction
Service_Score
Years_Since_Accred
2
2
2
2
2
2
2
195.00
72.50
53.50
2.85
79.00
67.00
6.00
21.21
17.68
2.12
0.07
2.83
0.71
1.41
180.00
60.00
52.00
2.80
77.00
66.50
5.00
210.00
85.00
55.00
2.90
81.00
67.50
7.00
Delhi1
Bed_Count
Doctor_Count
Avg_Wait_Time
Mortality_Rate
Patient_Satisfaction
Service_Score
Years_Since_Accred
1
1
1
1
1
1
1
520.00
210.00
50.00
2.60
79.00
68.80
9.00
.
.
.
.
.
.
.
520.00
210.00
50.00
2.60
79.00
68.80
9.00
520.00
210.00
50.00
2.60
79.00
68.80
9.00
Hyderabad2
Bed_Count
Doctor_Count
Avg_Wait_Time
Mortality_Rate
Patient_Satisfaction
Service_Score
Years_Since_Accred
2
2
2
2
2
2
2
200.00
67.50
41.50
1.90
88.50
77.25
5.00
70.71
17.68
4.95
0.28
0.71
2.62
1.41
150.00
55.00
38.00
1.70
88.00
75.40
4.00
250.00
80.00
45.00
2.10
89.00
79.10
6.00
Kolkata1
Bed_Count
Doctor_Count
Avg_Wait_Time
Mortality_Rate
Patient_Satisfaction
Service_Score
Years_Since_Accred
1
1
1
1
1
1
1
260.00
100.00
42.00
2.00
84.00
75.00
6.00
.
.
.
.
.
.
.
260.00
100.00
42.00
2.00
84.00
75.00
6.00
260.00
100.00
42.00
2.00
84.00
75.00
6.00
Mumbai2
Bed_Count
Doctor_Count
Avg_Wait_Time
Mortality_Rate
Patient_Satisfaction
Service_Score
Years_Since_Accred
2
2
2
2
2
2
2
265.00
97.50
31.50
1.60
92.00
82.55
5.50
190.92
74.25
4.95
0.42
2.83
3.89
3.54
130.00
45.00
28.00
1.30
90.00
79.80
3.00
400.00
150.00
35.00
1.90
94.00
85.30
8.00
Pune1
Bed_Count
Doctor_Count
Avg_Wait_Time
Mortality_Rate
Patient_Satisfaction
Service_Score
Years_Since_Accred
1
1
1
1
1
1
1
220.00
90.00
40.00
2.30
86.00
75.50
7.00
.
.
.
.
.
.
.
220.00
90.00
40.00
2.30
86.00
75.50
7.00
220.00
90.00
40.00
2.30
86.00
75.50
7.00
Visakhapatnam1
Bed_Count
Doctor_Count
Avg_Wait_Time
Mortality_Rate
Patient_Satisfaction
Service_Score
Years_Since_Accred
1
1
1
1
1
1
1
190.00
70.00
47.00
2.40
83.00
71.90
5.00
.
.
.
.
.
.
.
190.00
70.00
47.00
2.40
83.00
71.90
5.00
190.00
70.00
47.00
2.40
83.00
71.90
5.00

6. CORRELATION ANALYSIS USING PROC CORR

proc corr data=work.hospital_scored

          nosimple

          plots=none;

  var Bed_Count Doctor_Count Avg_Wait_Time Mortality_Rate 

      Patient_Satisfaction Service_Score Years_Since_Accred;

run;

OUTPUT:

The CORR Procedure

7 Variables:Bed_Count Doctor_Count Avg_Wait_Time Mortality_Rate Patient_Satisfaction Service_Score Years_Since_Accred
Pearson Correlation Coefficients, N = 12
Prob > |r| under H0: Rho=0
 Bed_CountDoctor_CountAvg_Wait_TimeMortality_RatePatient_SatisfactionService_ScoreYears_Since_Accred
Bed_Count
1.00000
 
0.99056
<.0001
0.04148
0.8982
0.10836
0.7375
-0.15547
0.6295
-0.09845
0.7608
0.85997
0.0003
Doctor_Count
0.99056
<.0001
1.00000
 
0.06091
0.8508
0.14741
0.6475
-0.21388
0.5045
-0.13665
0.6719
0.86329
0.0003
Avg_Wait_Time
0.04148
0.8982
0.06091
0.8508
1.00000
 
0.95582
<.0001
-0.93218
<.0001
-0.98414
<.0001
0.06230
0.8475
Mortality_Rate
0.10836
0.7375
0.14741
0.6475
0.95582
<.0001
1.00000
 
-0.95078
<.0001
-0.98295
<.0001
0.20446
0.5239
Patient_Satisfaction
-0.15547
0.6295
-0.21388
0.5045
-0.93218
<.0001
-0.95078
<.0001
1.00000
 
0.97773
<.0001
-0.20871
0.5151
Service_Score
-0.09845
0.7608
-0.13665
0.6719
-0.98414
<.0001
-0.98295
<.0001
0.97773
<.0001
1.00000
 
-0.14969
0.6424
Years_Since_Accred
0.85997
0.0003
0.86329
0.0003
0.06230
0.8475
0.20446
0.5239
-0.20871
0.5151
-0.14969
0.6424
1.00000
 

7. VISUALIZATION USING PROC SGPLOT

proc sgplot data=work.hospital_scored;

  title "Hospital Service Score vs Average Wait Time by City";

  scatter x=Avg_Wait_Time y=Service_Score / group=City datalabel=Hospital_Name;

  xaxis label="Average Wait Time (minutes)";

  yaxis label="Service Score";

run;

OUTPUT:

The SGPlot Procedure

/*Bar chart of service score by hospital */

proc sgplot data=work.hospital_scored;

  title "Service Score by Hospital";

  vbar Hospital_Name / response=Service_Score datalabel;

  xaxis display=(nolabel);

  yaxis label="Service Score";

run;

OUTPUT:
The SGPlot Procedure





To Visit My Previous Online Streaming Flatform Dataset:Click Here
To Visit My Previous Statistical Evaluation Of Clinical Trials:Click Here
To Visit My Previous Unlocking Retail Insights Dataset:Click Here
To Visit My Previous Sas Interview Questions-1:Click Here  



Follow Us On : 


 


--- FOLLOW OUR BLOG FOR MORE INFORMATION.

--->PLEASE DO COMMENTS AND SHARE OUR BLOG.



No comments:

Post a Comment