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.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 3201 views
  • 3 likes
  • 3 in conversation