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 2025: Register Now

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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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