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

Hi, I'm having trouble in getting the exact series plots that I want. 

Particularly, I want add a refline at March 2020, but the plot only does not show Mar in 2020. 

Here is the dataset that I made up and what I did to make the plots

data input1;
	input monthlyyear :date9. amount type;
	format monthlyyear date9.;
	datalines;
	01JAN2016 4 1
	01FEB2016 6 3
	01MAR2016 5 2
	01APR2016 39 2
	01MAY2016 49 1
	01JUN2016 34 3
	01JUL2016 49 2
	01AUG2016 30 1
	01SEP2016 30 2
	01OCT2016 2 3
	01NOV2016 34 3
	01DEC2016 30 3
	01JAN2017 56 2
	01FEB2017 45 1
	01MAR2017 45 1
	01APR2017 34 2
	01MAY2017 45 3
	01JUN2017 45 2
	01JUL2017 23 2
	01AUG2017 26 1
	01SEP2017 45 2
	01OCT2017 35 1
	01NOV2017 67 2
	01DEC2017 20 3
	01JAN2018 34 3
	01FEB2018 56 2
	01MAR2018 67 3
	01APR2018 20 2
	01MAY2018 29 3
	01JUN2018 24 2
	01JUL2018 49 2
	01AUG2018 32 1
	01SEP2018 27 1
	01OCT2018 24 2
	01NOV2018 28 3
	01DEC2018 35 2
	01JAN2019 45 3
	01FEB2019 74 2
	01MAR2019 73 1
	01APR2019 83 1 
	01MAY2019 82 3
	01JUN2019 85 2
	01JUL2019 43 3
	01AUG2019 82 2
	01SEP2019 62 1
	01OCT2019 74 3
	01NOV2019 35 3
	01DEC2019 65 3
	01JAN2020 45 2
	01FEB2020 4 2
	01MAR2020 94 2
	01APR2020 82 1
	01MAY2020 84 2
	01JUN2020 71 3
	01JUL2020 32 3
	01AUG2020 24 2
	01SEP2020 74 2
	01OCT2020 15 3
	01NOV2020 34 2
	01DEC2020 65 2
	; 
run;

proc print data=input1;
run;
proc sgplot data=input1 ;
	title "graph for input1";
	series x=monthlyyear y=amount /group=type lineattrs=(thickness=1);
	xaxis grid interval=month label="Month and Year"; 
	yaxis grid valueshint label="Expenditure";
	format MonthlyYear yymon7.;
run;

Here is the plots that I get.

Screen Shot 2022-10-13 at 7.02.28 PM.png

I want to add refline at Apr 2016, Jun 2017, Oct 2018, Aug 2019, and Mar 2020. Since Aug and Mar are not shown in the axis, I don't know how to add refline. I'm also wonder if I'm able to add short description on those reflines.

In addition, I also want to make the three lines as different dashed so that when I print it out black and white, I'm able to distinguish which line is which. 

Any suggestions is appreciated!!

  

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

First thing, that is 5 reflines not 3.

Here's how to do 2 with different appearance. You should be able to add the rest following the pattern.

 

proc sgplot data=input1 ;
	title "graph for input1";
	series x=monthlyyear y=amount /group=type lineattrs=(thickness=1);
	xaxis grid interval=month label="Month and Year"; 
	yaxis grid valueshint label="Expenditure";
	format MonthlyYear yymon7.;
   refline '01Apr2016'd  /axis=x label='Label for Apr 2016' lineattrs=(pattern=10 color=blue thickness= .5mm);
   refline '01MAR2020'd  /axis=x label='Label for Mar 2020' lineattrs=(pattern=1 color=red thickness=1mm);
run;

There are additional options in REFLINE documentation to control the text of the label and to position the label.

The LINEATTRS documentation will link to specific examples and the Pattern definitions that control the line appearance. There are about a dozen named line patterns like Solid dot dash dotdashdot shortdash or 46 numbers with 1 being a solid line.

 

 

View solution in original post

4 REPLIES 4
ballardw
Super User

First thing, that is 5 reflines not 3.

Here's how to do 2 with different appearance. You should be able to add the rest following the pattern.

 

proc sgplot data=input1 ;
	title "graph for input1";
	series x=monthlyyear y=amount /group=type lineattrs=(thickness=1);
	xaxis grid interval=month label="Month and Year"; 
	yaxis grid valueshint label="Expenditure";
	format MonthlyYear yymon7.;
   refline '01Apr2016'd  /axis=x label='Label for Apr 2016' lineattrs=(pattern=10 color=blue thickness= .5mm);
   refline '01MAR2020'd  /axis=x label='Label for Mar 2020' lineattrs=(pattern=1 color=red thickness=1mm);
run;

There are additional options in REFLINE documentation to control the text of the label and to position the label.

The LINEATTRS documentation will link to specific examples and the Pattern definitions that control the line appearance. There are about a dozen named line patterns like Solid dot dash dotdashdot shortdash or 46 numbers with 1 being a solid line.

 

 

LisaZ1
Obsidian | Level 7
Thanks for your suggestion. it solved my problem.
Sorry I wasn't being very clear about my needs. When I said 3 lines, I mean the 3 line with different types (green, blue, and red). To be more specific, I want them to be in 3 different kinds of dashed line so that when I print it out using Black&White printer, I'm able to distinguish which one is which.
Thank you!
Reeza
Super User

You may also want to look at BANDS BLOCKS to have shaded bands in the graph instead. I find it's easier chart to read if the background colour changes instead of reflines.

See the Results tab here: https://support.sas.com/kb/42/893.html (GPLOT)

SGPLOT solution with BLOCK https://communities.sas.com/t5/Graphics-Programming/sgplot-shading-background-of-a-plot/td-p/825632

ballardw
Super User

@LisaZ1 wrote:
Thanks for your suggestion. it solved my problem.
Sorry I wasn't being very clear about my needs. When I said 3 lines, I mean the 3 line with different types (green, blue, and red). To be more specific, I want them to be in 3 different kinds of dashed line so that when I print it out using Black&White printer, I'm able to distinguish which one is which.
Thank you!

It may be a good idea to mark the message that solves your problem. That way someone else searching the forum or getting here from a search engine can tell the question was solved.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 757 views
  • 4 likes
  • 3 in conversation