BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Nikolakis
Calcite | Level 5

Hello - Can you please help me? Below is the code for a bar-line chart using proc sgplot. The problem I have is that the refline on the x axis does not appear at the right date. It shows in the beginning of the data range of dates. How can I make it appear at the specified value in the refline statement?

proc sgplot data=w;
format IncrementalUFOnly comma10. BaseUSalesFOnly comma10.;
  vbar WeekEnd /response=IncrementalUFOnly dataskin=pressed baselineattrs=(thickness=0) fillattrs=graphdata1 name='a';
  vline WeekEnd / response=BaseUSalesFOnly lineattrs=(pattern=solid color=gold thickness=2) name='b' ;
  xaxis values=('06Jan2019'd to '04Aug2019'd by Week) display=(noline nolabel noticks)  fitpolicy=rotatethin
                                                      valuesrotate=vertical labelattrs=( size=7pt ) valueattrs=( size=10pt );
  refline '16Jun2019'd / axis=x lineattrs=(color=red pattern=shortdash) transparency=0.1 noclip ;
  yaxis display=(noline noticks) grid label='Incremental Units Feature Only' values=(0 to 85000 by 5000) offsetmin=0;
  keylegend 'a' 'b'/ title ='' linelength=24 valueattrs=(size=8pt);
  format WeekEnd MMDDYY10.;
run;
ods graphics off;
Title1;

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

@Nikolakis wrote:

Hello - Thank you for getting back to me. I tried that and still does not work - no reflines appear. Below please see my code:

(...)
     refline '09Jun2019' '16Jun2019' / axis=x lineattrs=(color=red pattern=dot);
(...)


No, you didn't really try my suggestion, but used format DATE9. rather than MMDDYY10. Please reread my REFLINE statement and use the same date format in your code, i.e. '06/09/2019' '06/16/2019'.

View solution in original post

4 REPLIES 4
FreelanceReinh
Jade | Level 19

Hello @Nikolakis and welcome to the SAS Support Communities!

 

According to this 2017 post you need to specify the value as a formatted value in the format that is used for the corresponding variable (WeekEnd), i.e. MMDDYY10., because it's a discrete axis. So, this should work:

refline '06/16/2019' / axis=x ...;

(I've tested it successfully with other data.)

Nikolakis
Calcite | Level 5

Hello - Thank you for getting back to me. I tried that and still does not work - no reflines appear. Below please see my code:

 

ods graphics on;
Title1 'Walgreens - Incremental Units Feature Only and Base Units Feature Only';
proc sgplot data=w;
format IncrementalUFOnly comma10. BaseUSalesFOnly comma10.;
   vbar WeekEnd /response=IncrementalUFOnly dataskin=pressed baselineattrs=(thickness=0) fillattrs=graphdata1 name='a' nostatlabel;
   vline WeekEnd / response=BaseUSalesFOnly lineattrs=(pattern=solid color=gold thickness=2) nostatlabel name='b';
  xaxis values=('06Jan2019'd to '04Aug2019'd by Week) display=(noline nolabel noticks)  fitpolicy=rotatethin
                                                      valuesrotate=vertical labelattrs=( size=7pt ) valueattrs=( size=10pt );                                                   
  yaxis display=(noline noticks) grid label='Incremental and Base Units - Feature Only' values=(0 to 85000 by 5000) offsetmin=0;
     refline '09Jun2019' '16Jun2019' / axis=x lineattrs=(color=red pattern=dot);
  keylegend 'a' 'b'/ title ='' linelength=24 valueattrs=(size=8pt);
  format WeekEnd MMDDYY10.;
run;
ods graphics off;
Title1;

 

FreelanceReinh
Jade | Level 19

@Nikolakis wrote:

Hello - Thank you for getting back to me. I tried that and still does not work - no reflines appear. Below please see my code:

(...)
     refline '09Jun2019' '16Jun2019' / axis=x lineattrs=(color=red pattern=dot);
(...)


No, you didn't really try my suggestion, but used format DATE9. rather than MMDDYY10. Please reread my REFLINE statement and use the same date format in your code, i.e. '06/09/2019' '06/16/2019'.

Nikolakis
Calcite | Level 5

 It did work. Thank you very much!

sas-innovate-2024.png

 

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 2365 views
  • 0 likes
  • 2 in conversation