Hi All,
I'm want to create an XSchart.
The chart was split into 4 instead of 1. Please how do I make this come out as just 1 chart?
The data points for the subgroup variable are 09/01/2020, 10/01/2020,...01/01/2021
Please see the code.
title "Length of Stay";
symbol v=dot;
proc shewhart data=work.nowsbaseline_sorted;
xschart neonatald*measureperiodid/haxis= '01SEP2020'd to '01MAR2021'd by 31;
run;
Any help is greatly appreciated.
Thanks in advance!
Since I am not going to type in your screen captures of data, I made up my own data to illustrate.
data have;
input measureperiodid :date9. neonatald;
format measureperiodid date9.;
cards;
01OCT2020 40
01NOV2020 3
01DEC2020 19
01FEB2021 40
;
proc sql;
create table minmax as
select min(measureperiodid) as mindate,max(measureperiodid) as maxdate
from have;
run;
/* Create index values */
data index;
set minmax;
index=0;
date=mindate;
do until (date>=maxdate);
date=intnx('month',mindate,index,'b');
index=index+1;
year=year(date);
month=month(date);
output;
end;
format date date9.;
keep index date year month;
run;
data final;
merge have index(rename=(date=measureperiodid));
by measureperiodid;
if missing(neonatald) then neonatald=0;
run;
proc shewhart data=final;
irchart neonatald*index(year month)/blockpos=3 haxis=1 to 6;
label year='Year' month='Month';
run;
As I suggested in your other thread, make the horizontal axis to be the numbers 1, 2, ... and then use a block variable to identify the months.
Also note that using by 31 in your code, you will not really be displaying months, but time periods of 31 days.
Assigning index numbers can be automated.
Show me a portion of your data. Explain what changes from month to month that it would need automation.
@PaigeMiller This is an initiative implemented in hospitals. Each hospital reports the number of days a patient stays in the hospital every month. The goal is to create these control charts every month to see how effective the initiative is, so the neonatald variable changes every month.
Since I am not going to type in your screen captures of data, I made up my own data to illustrate.
data have;
input measureperiodid :date9. neonatald;
format measureperiodid date9.;
cards;
01OCT2020 40
01NOV2020 3
01DEC2020 19
01FEB2021 40
;
proc sql;
create table minmax as
select min(measureperiodid) as mindate,max(measureperiodid) as maxdate
from have;
run;
/* Create index values */
data index;
set minmax;
index=0;
date=mindate;
do until (date>=maxdate);
date=intnx('month',mindate,index,'b');
index=index+1;
year=year(date);
month=month(date);
output;
end;
format date date9.;
keep index date year month;
run;
data final;
merge have index(rename=(date=measureperiodid));
by measureperiodid;
if missing(neonatald) then neonatald=0;
run;
proc shewhart data=final;
irchart neonatald*index(year month)/blockpos=3 haxis=1 to 6;
label year='Year' month='Month';
run;
Let me alert you to change a small part of the above code, removing HAXIS=1 TO 6, as most likely you will have more than 6 months in your real data.
Don't know if this will fix the specific issue by I think you may have "nicer" axis appearance if you use
xschart neonatald*measureperiodid/haxis= '01SEP2020'd to '01MAR2021'd by month;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.