BookmarkSubscribeRSS Feed
Sagarg
Fluorite | Level 6

Used SGPLOT polygon but it gives not whole rectangle form.

4 REPLIES 4
Rick_SAS
SAS Super FREQ

Please post your code (and data, if you can) and explain what you are trying to accomplish. 

 

If it helps, the coordinates for the POLYGON statement are in the data coordinate system. So if you want a rectangle that goes from 28% of the data range to 50% of the data range, you can use PROC MEANS to compute the min and max values of the coordinates, then use a DATA step to create the rectangle corners, which will have the values

XMin_Poly = XMin + 0.28*(XMax - XMin);

XMax_Poly = XMin + 0.5*(XMax - XMin);

The Y coordinates are computed similarly.

 

Jay54
Meteorite | Level 14

I too prefer using POLYGON plot in data coordinates as suggested by Rick.  This is good if you want the figures to be represented in the legend, or be displayed in correct order.  If this is not required, annotation is an alternative. In that case you can use SGAnnotation (or %SGANNO macros) in DataPercent drawspace.

DanH_sas
SAS Super FREQ

I had the same thought as @Jay54 , because you can use DATAPERCENT as a drawing space. Here is a simple example:

 

data anno;
length function $ 9 drawspace $ 11 anchor $ 10;
function="rectangle";
drawspace="datapercent";
anchor="bottomleft";
x1=28;
y1=29;
width=22;
height=21;
output;
run;

proc sgplot data=sashelp.class sganno=anno;
scatter x=weight y=height;
run;
ballardw
Super User

@Sagarg wrote:

Used SGPLOT polygon but it gives not whole rectangle form.


It is usually a good idea to include the code you attempted and describe what you need that the code isn't doing.

In the case of polygon the actual data step or file used is important.

An improperly shaped polygon would likely result from a missing vertex or an ID variable misaligned with the x and y coordinates.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

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
  • 4 replies
  • 474 views
  • 4 likes
  • 5 in conversation