BookmarkSubscribeRSS Feed
BrianOwens
Calcite | Level 5

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:

 
BrianOwens_1-1654265130308.png

 

 

5 REPLIES 5
ballardw
Super User

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.

 

BrianOwens
Calcite | Level 5
Here is an example of the data

Unit Start1 End1 Phase1
Unit 1 1-Oct-22 31-Mar-23 Committed
Unit 2 1-Oct-22 31-Mar-23 Committed
Unit 3 1-Apr-23 30-Sep-23 Committed
Unit 4 1-Apr-23 30-Sep-23 Committed
Unit 5 1-Oct-23 31-Mar-24 Committed
Unit 6 1-Oct-23 31-Mar-24 Committed
Unit 7 1-Apr-24 30-Sep-24 Committed
Unit 8 1-Apr-24 30-Sep-24 Committed
Unit 9 1-Oct-24 30-Sep-25 Committed
Unit 10 1-Oct-24 30-Sep-25 Committed
BrianOwens
Calcite | Level 5
UnitStart1End1Phase1Start2End2Phase2Start3End3Phase3Start4End4Phase 4
Unit 11-Oct-2231-Mar-23Committed1-Apr-2330-Sep-23Reset1-Oct-2331-Mar-24Prepare1-Apr-2430-Sep-24Ready
Unit 21-Oct-2231-Mar-23Committed1-Apr-2330-Sep-23Reset1-Oct-2331-Mar-24Prepare1-Apr-2430-Sep-24Ready
Unit 31-Apr-2330-Sep-23Committed1-Oct-2330-Mar-24Reset1-Apr-2430-Sep-24Prepare1-Oct-2430-Mar-25Ready
Unit 41-Apr-2330-Sep-23Committed1-Oct-2330-Mar-24Reset1-Apr-2430-Sep-24Prepare1-Oct-2430-Mar-25Ready
Unit 51-Oct-2331-Mar-24Committed1-Apr-2430-Sep-24Reset1-Oct-2430-Mar-25Prepare1-Apr-2530-Sep-25Ready
Unit 61-Oct-2331-Mar-24Committed1-Apr-2430-Sep-24Reset1-Oct-2430-Mar-25Prepare1-Apr-2530-Sep-25Ready
Unit 71-Apr-2430-Sep-24Committed1-Oct-2431-Mar-25Reset1-Apr-2530-Sep-25Prepare1-Oct-2530-Mar-26Ready
Unit 81-Apr-2430-Sep-24Committed1-Oct-2431-Mar-25Reset1-Apr-2530-Sep-25Prepare1-Oct-2530-Mar-26Ready
Unit 91-Oct-2430-Mar-25Committed1-Apr-2530-Sep-25Reset1-Oct-2531-Mar-26Prepare1-Apr-2630-Sep-26Ready
Unit 101-Oct-2431-Mar-25Committed1-Apr-2530-Sep-25Reset1-Oct-2531-Mar-26Prepare1-Apr-2630-Sep-26Ready
BrianOwens
Calcite | Level 5

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.

ballardw
Super User

@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;

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 989 views
  • 0 likes
  • 2 in conversation