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

Hi,

I'm using sgplot to create a vertical bar chart with a monyy5. formatted date as the X axis. I need to include a vertical reference line on one date value but I'm having trouble getting the line to show up correctly. Below is some test code to recreate the problem. Any help is much appreciated!

Thanks,

John

/* create date values */

data test;

   do date = today()-30 to today();

      date2 = date;

      output;

   end;

   format date2 monyy5.;

run;

proc print data=test(obs=5);

run;

/* plot unformatted */

title 'Not formatted - refline shows up';

proc sgplot data=test;

   vbar date;

   refline '01SEP2014'd / axis=x labelloc=outside lineattrs=(color=red) label='TEST';

run;

/* plot MONYY5. formatted */

title 'MONYY5. format - refline does not show';

title2 'And the label is on the wrong month';

proc sgplot data=test;

   vbar date2;

   refline '01SEP2014'd / axis=x labelloc=outside lineattrs=(color=red) label='TEST';

run;

title;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Use:

refline 'Sep14' / axis=x labelloc=outside lineattrs=(color=red) label='TEST' ;

in the second plot. References must appear as the FORMATTED value, not the value.

A better example would have been as then you are using same variable and values to display with the only difference the format:

proc sgplot data=test;                                                                                                               

   vbar date;                                                                                                                        

   format date date9.;                                                                                                               

   refline '01SEP2014'd / axis=x labelloc=outside lineattrs=(color=red) label='TEST';                                                

run;        

See what happens when you use the option NOCLIP in the refline  for more entertainment. 

You might want to change the datastep to have:

do date = '15AUG2014'd to '16SEP2014'd;

so that the data stays the same when the program is run on different dates.

One would expect problems with the refline in September when the program is run in December for example due to clipping of the axis.

View solution in original post

3 REPLIES 3
ballardw
Super User

Use:

refline 'Sep14' / axis=x labelloc=outside lineattrs=(color=red) label='TEST' ;

in the second plot. References must appear as the FORMATTED value, not the value.

A better example would have been as then you are using same variable and values to display with the only difference the format:

proc sgplot data=test;                                                                                                               

   vbar date;                                                                                                                        

   format date date9.;                                                                                                               

   refline '01SEP2014'd / axis=x labelloc=outside lineattrs=(color=red) label='TEST';                                                

run;        

See what happens when you use the option NOCLIP in the refline  for more entertainment. 

You might want to change the datastep to have:

do date = '15AUG2014'd to '16SEP2014'd;

so that the data stays the same when the program is run on different dates.

One would expect problems with the refline in September when the program is run in December for example due to clipping of the axis.

jnvickery
Obsidian | Level 7

Thanks!

Both solutions worked great (looks like I can only mark a single reply as "Correct Answer"):

refline 'Sep14' / axis=x labelloc=outside lineattrs=(color=red) label='TEST' ;

and

refline myreflines / axis=x labelloc=outside lineattrs=(color=red) label='TEST';

DanH_sas
SAS Super FREQ

Unfortunately, literal REFLINE values do not pick up formats from the axis and you currently cannot set a format for a literal REFLINE value. However, you CAN work around this by putting your REFLINEs in a data column, setting your format on that column and referring to that column from the REFLINE statement:

   refline myreflines / axis=x labelloc=outside lineattrs=(color=red) label='TEST';

Hope this helps!

Dan

SAS INNOVATE 2024

Innovate_SAS_Blue.png

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. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 3010 views
  • 3 likes
  • 3 in conversation