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;
@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'.
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.)
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;
@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'.
It did work. Thank you very much!
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.