BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
AndersS
Lapis Lazuli | Level 10

Hi!  I want to add a vertical line and also a horizontal line, both of specific length,

very close to the Y-axis  resp. X-axis in Proc SGPLOT.

At present I do this on the PC using PAINT.NET (from Microsoft).

(On the PC: name.svg --> take out the picture as   screencopy.jpg  file. Use Paint.net).


It works, but you can see on the details of the lines that my hand is not quite steady.
If possible I would like to specify the length and the position in SGPLOT.

Fig4B E3 MM.png

 

Perhaps there is a better software than PAINT.net  to draw straight lines on a graph?

Many thanks in advance!

/Br Anders

 

Anders Sköllermo (Skollermo in English)
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

How exactly are you specifying "length"?

 

Adding coordinates for a Series or perhaps a Vector plot would be my idea. Here is an example placing a horizontal line. Provide a different pair of x and y variables for a vertical line. Note that I have cleverly picked a value for y of the horizontal line that is just above the starting value of the Yaxis values= list. If the space between is still too large you could use y values like 55.01 or what appears good to you.

data myline;
   input xline yline;
datalines;
55 55.1
68 55.1
;

data toplot;
   set sashelp.class
       myline
   ;
run;

proc sgplot data=toplot;
   scatter x=height y=weight;
   series x=xline y=yline;
   xaxis values=(50 to 70 by 5);
   yaxis values=(55 to 135 by 20);
run;

You could use the LINEATTRS option on the series for Xline and Yline to set color, linewidth and even a type as desired.

View solution in original post

9 REPLIES 9
Reeza
Super User

Use the LINEPARM statement in SGPLOT if you know ahead of time where you want to draw the lines. 

 

LINEPARM

Creates a straight line specified by a point and a slope. You can generate a single line by specifying a constant for each required argument. You can generate multiple lines by specifying a numeric variable for any or all required arguments.


EDIT: to limit the line, POLYGON may be better. Either way, I'd use some functionality within PROC SGPLOT to get it created.

 

 

AndersS
Lapis Lazuli | Level 10
HI! It works as is nice.
Anders Sköllermo (Skollermo in English)
ballardw
Super User

How exactly are you specifying "length"?

 

Adding coordinates for a Series or perhaps a Vector plot would be my idea. Here is an example placing a horizontal line. Provide a different pair of x and y variables for a vertical line. Note that I have cleverly picked a value for y of the horizontal line that is just above the starting value of the Yaxis values= list. If the space between is still too large you could use y values like 55.01 or what appears good to you.

data myline;
   input xline yline;
datalines;
55 55.1
68 55.1
;

data toplot;
   set sashelp.class
       myline
   ;
run;

proc sgplot data=toplot;
   scatter x=height y=weight;
   series x=xline y=yline;
   xaxis values=(50 to 70 by 5);
   yaxis values=(55 to 135 by 20);
run;

You could use the LINEATTRS option on the series for Xline and Yline to set color, linewidth and even a type as desired.

AndersS
Lapis Lazuli | Level 10

Hi! I used one "SERIES" for each line. Works VERY well.

 

I asked one "stupid question" and reived three (3) VERY GOOD answers! ALL of them are working.

This one is perhaps the simplest. But all solutions are of GREAT interest.

MANY THANKS!

/Br Anders

Anders Sköllermo (Skollermo in English)
Ksharp
Super User
%sganno
data sganno;
 %SGLINE(X1=0,Y1=0,X2=50,Y2=0,DRAWSPACE="DATAPERCENT" ,LINECOLOR="black" ,LINETHICKNESS=6)
 %SGLINE(X1=0,Y1=25,X2=0,Y2=50,DRAWSPACE="DATAPERCENT" ,LINECOLOR="black" ,LINETHICKNESS=6)
run;


data have;
 set sashelp.stocks;
 if stock='IBM';
run;
proc sgplot data=have noautolegend sganno=sganno;
loess x=date y=close;
xaxis offsetmin=0.01 ;
yaxis offsetmin=0.01 ;
run;

Ksharp_0-1689680189380.png

 

AndersS
Lapis Lazuli | Level 10

GANNO solution works well. The "SERIES" solution is simpler.

BUT - I know now how to use GANNO ans similar. VERY useful.

MANY THANKS!

Anders Sköllermo (Skollermo in English)
AndersS
Lapis Lazuli | Level 10

Hi! Do you have any good examples of the use of %SGTEXT ?

 

Your suggestion eralier was very useful, even if another one was simpler to use.

/Br Anders

 

Anders Sköllermo (Skollermo in English)
AndersS
Lapis Lazuli | Level 10

Many Thanks!

Anders Sköllermo (Skollermo in English)

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

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
  • 9 replies
  • 3485 views
  • 9 likes
  • 4 in conversation