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

Does Proc Ginside require that the vertices of a custom polygon be ordered?  If so, what is the appropriate order?  Is there an easy way to accomplish this?

Thanks,

Gene

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@genemroz wrote:

Does Proc Ginside require that the vertices of a custom polygon be ordered?  If so, what is the appropriate order?  Is there an easy way to accomplish this?

Thanks,

Gene


Pretty much. To make sure a polygon is usable the last point on the perimeter must have the same coordinates as the first.

 

How to accomplish may depend. Can you provide more information? What sort of "custom polygon" do you envision?

 

Basically a data set with the coordinates and polygon id information .

 

Ginside may not return your expected values if your custom polygon overlaps others. I seem to remember some difficulty with that but it has been a long time since that project.

View solution in original post

3 REPLIES 3
ballardw
Super User

@genemroz wrote:

Does Proc Ginside require that the vertices of a custom polygon be ordered?  If so, what is the appropriate order?  Is there an easy way to accomplish this?

Thanks,

Gene


Pretty much. To make sure a polygon is usable the last point on the perimeter must have the same coordinates as the first.

 

How to accomplish may depend. Can you provide more information? What sort of "custom polygon" do you envision?

 

Basically a data set with the coordinates and polygon id information .

 

Ginside may not return your expected values if your custom polygon overlaps others. I seem to remember some difficulty with that but it has been a long time since that project.

genemroz
Quartz | Level 8

Thanks for the prompt response.  I was looking for confirmation for what I already suspected to be the case.  I think I can figure it out from here....

 

Gene

Ksharp
Super User

Yes. the sequence/order of scatter points to plot a polygon is important.

Make sure you could get a right polygon by ploting these points one by one.

Here is an example:

 

/*产生样本数据*/
data have;
  pi=constant('PI');
  call streaminit(123);
    do i=1 to 500;
      x=40+30*ranuni(2);  y=40+40*ranuni(2); output;
    end;

    /*--Add data all over--*/
    do i=1 to 100;
      x=400*ranuni(2);  y=400*ranuni(2); output;
    end;

    /*--Add data in the middle fan--*/
    do i=1 to 5000;
      x=40+360*ranuni(2);  
	  y=x+(x-50)*2*tan(pi/4 *ranuni(2) -pi/8);
	  y=ifn(y>400 or y<0, ., y);
      output;
    end;
	x=70;y=84;output;
    x=70;y=56;output;
 keep x y;
run;










/*画图*/
/*--Generate grid and point data--*/
data map;
infile cards expandtabs;
input n id $ x y;
cards;
1	E_L 180 0
2	E_L 180 70
3	E_L 400 70
4	E_L 400 0
40	E_U 0 180
41	E_U 70 180
42	E_U 70 400
43	E_U 0 400
8	D_L  240 70
9	D_L  240 180
10	D_L  400 180
11	D_L  400 70
35	D_U 0 70
36	D_U 58.3 70
37	D_U 70 84
38	D_U 70 180
39	D_U 0 180
5	C_L  130 0
6	C_L  180 70
7	C_L  180 0
32	C_U 70 180
33	C_U 290 400
34	C_U 70 400
12	B_L  70 0
13	B_L  70 56
14	B_L  400 320
15	B_L  400 180
16	B_L  240 180
17	B_L  240 70
18	B_L  180 70
19	B_L  130 0
28	B_U 70 84
29	B_U 333 400
30	B_U 290 400
31	B_U 70 180
20	A 0 0
21	A 0 70
22	A 58.3 70
23	A 333 400
24	A 400 400
25	A 400 320
26	A 70 56
27	A 70 0
;
run;
data map;
 set map;
 if n in (23 29) then x=400/1.2 ;
 if n in (22 36) then x=70/1.2 ;
 drop n;
run;



/*判断点在哪个区域*/
proc ginside data=have map=map out=id INCLUDEBORDER;
  id id ;
run;
data id;
 set id;
 id=scan(id,1,'_');
run;
/*特殊情况判断
data id;
 set id;
 if not missing(y) and not missing(x) then do;
  if (abs(y-x)/x*100)<=20 then id='A';
 end;
run;
*/
proc freq data=id ;
table id/out=zone;
run;

%let A=0.00;
%let B=0.00;
%let C=0.00;
%let D=0.00;
%let E=0.00;

%let count_A=0;
%let count_B=0;
%let count_C=0;
%let count_D=0;
%let count_E=0;

data _null_;
 set zone;
 if not missing(id) then do;
  call symputx(id,put(PERCENT,8.2));
  call symputx(cats('count_',id),COUNT);
 end;
run;



data Grid;
  /*--Zone A--*/
  id2=11; rfbg2=70;  sbg2=0; output;
  id2=11; rfbg2=70;  sbg2=56; output;
  id2=12; rfbg2=58.3;sbg2=70; output;
  id2=12; rfbg2=0;   sbg2=70; output;
  id2=13; rfbg2=70;   sbg2=84; output;
  id2=13; rfbg2=70;   sbg2=180; output;
  id2=13; rfbg2=0;   sbg2=180; output;

  /*--Zone E - Y--*/
  id2=3; rfbg2=70;  sbg2=180; output;
  id2=3; rfbg2=70;  sbg2=400; output;
  id2=3; rfbg2=0;   sbg2=400; output;
  /*--Zone E - X--*/
  id2=4; rfbg2=180;  sbg2=0; output;
  id2=4; rfbg2=180;  sbg2=70; output;
  id2=4; rfbg2=400;  sbg2=70; output;
  /*--Zone D - X--*/
  id2=5; rfbg2=240;  sbg2=70; output;
  id2=5; rfbg2=240;  sbg2=180; output;
  id2=5; rfbg2=400;  sbg2=180; output;
  /*--Zone C - Low--*/
  id2=6; rfbg2=130;  sbg2=0; output;
  id2=6; rfbg2=180;  sbg2=70; output;
  /*--Zone C - High--*/
  id2=7; rfbg2=70;  sbg2=180; output;
  id2=7; rfbg2=290; sbg2=400; output;
  /*--Zone B - High--*/
  id2=8; rfbg2=58.3; sbg2=70; output;
  id2=8; rfbg2=333.3;  sbg2=400; output;
  /*--Zone B - Low--*/
  id2=9; rfbg2=70;   sbg2=56; output;
  id2=9; rfbg2=400; sbg2=320; output;
  run;

data label;
length label $ 40;
    xl=20; yl=20; label='A';   output;
    xl=20; yl=120; label='D';  output;
    xl=20; yl=300; label='E';   output;
    xl=100; yl=20; label='B';   output;
    xl=160; yl=20; label='C';   output;
    xl=100; yl=160; label='B';   output;
    xl=320; yl=20; label="E(&count_E.,&E.%)";   output;
    xl=320; yl=120; label="D(&count_D.,&D.%)";  output;
    xl=320; yl=200; label="B(&count_B.,&B.%)" ; output;
    xl=340; yl=340; label="A(&count_A.,&A.%)" ; output;
    xl=120; yl=320; label="C(&count_C.,&C.%)" ; output;
run;


data plot;
 set Grid id label;
run;

/*--Attributes Map for zones--*/
data attrmap;
  length id $1 value $1 markercolor $10;
  id='A'; value='A'; markercolor='cx00afdf'; linecolor='cx00afdf'; output;
  id='A'; value='B'; markercolor='cx00ef7f'; linecolor='cx00ef7f'; output;
  id='A'; value='C'; markercolor='gray'; linecolor='gray'; output;
  id='A'; value='D'; markercolor='pink'; linecolor='pink'; output;
  id='A'; value='E'; markercolor='red'; linecolor='red'; output;
run;


/*--Draw the grid--*/
ods rtf file="c:\temp\clark.rtf" style=htmlblue dpi=300;
ods graphics / reset antialiasmax=5700 outputfmt=png;
proc sgplot data=plot noautolegend aspect=1 dattrmap=attrmap;
  scatter x=x y=y / attrid=A group=id  markerattrs=(symbol=circlefilled size=4 ) ;
  scatter x=xl y=yl / markerchar=label markercharattrs=(size=12)  ;
    series x=rfbg2 y=sbg2 / group=id2 lineattrs=(color=gray ) nomissinggroup;

  xaxis values=(0 to 400 by 50) offsetmin=0 offsetmax=0 label='Reference Blood Glucose';
  yaxis values=(0 to 400 by 50) offsetmin=0 offsetmax=0 label='Sensor Blood Glucose';
  run;
ods rtf close;

Ksharp_0-1730427907868.png

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 663 views
  • 1 like
  • 3 in conversation