I am trying to create a scheduled chart in SAS EG 7.1 showing how are units are scheduled for different Phases over a 5 year period. I have use the below code to get the first phase documented but what I want to show is all 4 phases presented on one line which each phase will be presented by a different color. Here is the code I used so far:
Proc sgplot data=WORK.'Chart Schedule Test'n;
title 'Wing Calander';
highlow y=UNIT low=START1 HIGH=END1 / type=bar group=PHASE1
groupdisplay=cluster barwidth=0.5 fillattrs=(color=bib) name='a';
yaxis reverse display=(nolabel) grid;
xaxis display=(nolabel) min='01oct2022'd max='30sep2026'd grid;
keylegend 'a' / location=inside position=topright across=1;
run;
What I want to do is add additional lines after the blue bars on the same line that will show additional phases they will be in. Similar to a Gantt chart but on the same line. Also, is there a way to show all months in the below axis. Thank you!
This was the output:
Share some example data for best results including multiple phases.
From this line of your code with the group variable name of Phase1
highlow y=UNIT low=START1 HIGH=END1 / type=bar group=PHASE1
you may have a suboptimal data structure for your requirement. The data likely should have a single variable Phase, that takes values of 1,2,3 etc. Then, if the data is structured correctly, Group=Phase would create a separate bar of a different color by default.
The other approach would require multiple plot statements, one for each "phase" with its own Group variable.
Unit | Start1 | End1 | Phase1 | Start2 | End2 | Phase2 | Start3 | End3 | Phase3 | Start4 | End4 | Phase 4 |
Unit 1 | 1-Oct-22 | 31-Mar-23 | Committed | 1-Apr-23 | 30-Sep-23 | Reset | 1-Oct-23 | 31-Mar-24 | Prepare | 1-Apr-24 | 30-Sep-24 | Ready |
Unit 2 | 1-Oct-22 | 31-Mar-23 | Committed | 1-Apr-23 | 30-Sep-23 | Reset | 1-Oct-23 | 31-Mar-24 | Prepare | 1-Apr-24 | 30-Sep-24 | Ready |
Unit 3 | 1-Apr-23 | 30-Sep-23 | Committed | 1-Oct-23 | 30-Mar-24 | Reset | 1-Apr-24 | 30-Sep-24 | Prepare | 1-Oct-24 | 30-Mar-25 | Ready |
Unit 4 | 1-Apr-23 | 30-Sep-23 | Committed | 1-Oct-23 | 30-Mar-24 | Reset | 1-Apr-24 | 30-Sep-24 | Prepare | 1-Oct-24 | 30-Mar-25 | Ready |
Unit 5 | 1-Oct-23 | 31-Mar-24 | Committed | 1-Apr-24 | 30-Sep-24 | Reset | 1-Oct-24 | 30-Mar-25 | Prepare | 1-Apr-25 | 30-Sep-25 | Ready |
Unit 6 | 1-Oct-23 | 31-Mar-24 | Committed | 1-Apr-24 | 30-Sep-24 | Reset | 1-Oct-24 | 30-Mar-25 | Prepare | 1-Apr-25 | 30-Sep-25 | Ready |
Unit 7 | 1-Apr-24 | 30-Sep-24 | Committed | 1-Oct-24 | 31-Mar-25 | Reset | 1-Apr-25 | 30-Sep-25 | Prepare | 1-Oct-25 | 30-Mar-26 | Ready |
Unit 8 | 1-Apr-24 | 30-Sep-24 | Committed | 1-Oct-24 | 31-Mar-25 | Reset | 1-Apr-25 | 30-Sep-25 | Prepare | 1-Oct-25 | 30-Mar-26 | Ready |
Unit 9 | 1-Oct-24 | 30-Mar-25 | Committed | 1-Apr-25 | 30-Sep-25 | Reset | 1-Oct-25 | 31-Mar-26 | Prepare | 1-Apr-26 | 30-Sep-26 | Ready |
Unit 10 | 1-Oct-24 | 31-Mar-25 | Committed | 1-Apr-25 | 30-Sep-25 | Reset | 1-Oct-25 | 31-Mar-26 | Prepare | 1-Apr-26 | 30-Sep-26 | Ready |
I am going to try your first suggestion. I tried creating sperate plot statements but it gives me separate outputs but I want it all on one.
@BrianOwens wrote:
I am going to try your first suggestion. I tried creating sperate plot statements but it gives me separate outputs but I want it all on one.
ANY time you get output other than desired include the entire text of the submitted code. Best is to copy from the LOG with any notes or messages, open a text box on the forum with the </> icon above the message box and paste the text.
The example data you show does give me clue why you might have problems: The X and Y AXIS variables would have to be the same. The data looks suspiciously like typical spreadsheet thinking which does not work well with SAS (or most other data systems).
Consider: This builds a data set from that text. Note use of 4 digit years. Use of 2-digit years is bad juju and can lead to a variety of unexpected oddness. Then reshapes the data to a form more suited to use for almost any purpose in SAS and Plots that data. I used a different format in the plot and depending on the display size of the graph may work nicer than what yours defaulted to.
data have; infile datalines dlm=','; input Unit $ Start1 :date11. End1 :date11. Phase1:$15. Start2 :date11. End2 :date11. Phase2:$15. Start3 :date11. End3 :date11. Phase3:$15. Start4 :date11. End4 :date11. Phase4:$15. ; format Start: End: date11.; datalines; Unit 1,1-Oct-2022,31-Mar-2023,Committed,1-Apr-2023,30-Sep-2023,Reset,1-Oct-2023,31-Mar-2024,Prepare,1-Apr-2024,30-Sep-2024,Ready Unit 2,1-Oct-2022,31-Mar-2023,Committed,1-Apr-2023,30-Sep-2023,Reset,1-Oct-2023,31-Mar-2024,Prepare,1-Apr-2024,30-Sep-2024,Ready Unit 3,1-Apr-2023,30-Sep-2023,Committed,1-Oct-2023,30-Mar-2024,Reset,1-Apr-2024,30-Sep-2024,Prepare,1-Oct-2024,30-Mar-2025,Ready Unit 4,1-Apr-2023,30-Sep-2023,Committed,1-Oct-2023,30-Mar-2024,Reset,1-Apr-2024,30-Sep-2024,Prepare,1-Oct-2024,30-Mar-2025,Ready Unit 5,1-Oct-2023,31-Mar-2024,Committed,1-Apr-2024,30-Sep-2024,Reset,1-Oct-2024,30-Mar-2025,Prepare,1-Apr-2025,30-Sep-2025,Ready Unit 6,1-Oct-2023,31-Mar-2024,Committed,1-Apr-2024,30-Sep-2024,Reset,1-Oct-2024,30-Mar-2025,Prepare,1-Apr-2025,30-Sep-2025,Ready Unit 7,1-Apr-2024,30-Sep-2024,Committed,1-Oct-2024,31-Mar-2025,Reset,1-Apr-2025,30-Sep-2025,Prepare,1-Oct-2025,30-Mar-2026,Ready Unit 8,1-Apr-2024,30-Sep-2024,Committed,1-Oct-2024,31-Mar-2025,Reset,1-Apr-2025,30-Sep-2025,Prepare,1-Oct-2025,30-Mar-2026,Ready Unit 9,1-Oct-2024,30-Mar-2025,Committed,1-Apr-2025,30-Sep-2025,Reset,1-Oct-2025,31-Mar-2026,Prepare,1-Apr-2026,30-Sep-2026,Ready Unit 10,1-Oct-2024,31-Mar-2025,Committed,1-Apr-2025,30-Sep-2025,Reset,1-Oct-2025,31-Mar-2026,Prepare,1-Apr-2026,30-Sep-2026,Ready ; data toplot; set have; array s (*) start: ; array e (*) end: ; array p (*) phase: ; do i= 1 to dim(s); start = s[i]; end = e[i]; phase = p[i]; output; end; format start end date11.; keep unit start end phase; run; proc sgplot data=toplot; title 'Wing Calander'; highlow y=UNIT low=START HIGH=END / type=bar group=PHASE groupdisplay=overlay barwidth=0.5 name='a'; yaxis reverse display=(nolabel) grid; /* xaxis display=(nolabel) min='01oct2022'd max='30sep2026'd grid;*/ xaxis display=(nolabel) values=('01oct2022'd to '01OCT2026'd by quarter) grid valuesformat=yymon. ; keylegend 'a' / location=inside position=topright across=1; run; title;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.