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

Dear programmers,

 

I like to give a character name in a SCATTER PLOT to some points which their position are in a certain area in the plot (with respect to X- and Y-axis).

 

In the following dataset, I want the points between 3<x<8 and 3<y<8 to have the label D, E, F and G.

 

data person;
infile datalines delimiter=',';
input name $ X Y;
datalines;
A, 1, 1
B, 2, 2
C, 3, 3
D, 4, 4
E, 5, 5
F, 6, 6
G, 7, 7
H, 8, 8
I, 9, 9
J, 10, 10
K, 11, 11
;

 

My code is:

 

%_eg_conditional_dropds(WORK.SORTTempTableSorted);

PROC SQL;
CREATE VIEW WORK.SORTTempTableSorted AS
SELECT T.X, T.Y
FROM WORK.PERSON as T
;
QUIT;
SYMBOL1
INTERPOL=NONE
HEIGHT=3pt
VALUE=CIRCLE
LINE=1
WIDTH=1

CV = _STYLE_
;
Axis1
STYLE=1
WIDTH=1
MINOR=NONE


;
Axis2
STYLE=1
WIDTH=1
MINOR=NONE


;
TITLE;
TITLE1 "Scatter Plot";
FOOTNOTE;
FOOTNOTE1 "Generated by the SAS System (&_SASSERVERNAME, &SYSSCPL) on %TRIM(%QSYSFUNC(DATE(), NLDATE20.)) at %TRIM(%SYSFUNC(TIME(), TIMEAMPM12.))";
PROC GPLOT DATA=WORK.SORTTempTableSorted
;
PLOT Y * X /
VAXIS=AXIS1

HAXIS=AXIS2

FRAME ;
RUN; QUIT;
%_eg_conditional_dropds(WORK.SORTTempTableSorted);
TITLE; FOOTNOTE;
GOPTIONS RESET = SYMBOL;

 

How can I modify the code to perform this job?

Best regards

 

Farshid Owrang 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

If I understand you correctly, here is a way

 

data person;
infile datalines delimiter=',';
input name $ X Y;
datalines;
A, 1, 1
B, 2, 2
C, 3, 3
D, 4, 4
E, 5, 5
F, 6, 6
G, 7, 7
H, 8, 8
I, 9, 9
J, 10, 10
K, 11, 11
;

data temp / view=temp;
    set person;
    if 3<x<8 and 3<y<8 then text=name;
    else do; sx=x; sy=y; end;
run;

proc sgplot data=temp;
    scatter x=sx y=sy;
    text x=x y=y text=text;
run;

Result:

 

 

Udklip.PNG

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

If I understand you correctly, here is a way

 

data person;
infile datalines delimiter=',';
input name $ X Y;
datalines;
A, 1, 1
B, 2, 2
C, 3, 3
D, 4, 4
E, 5, 5
F, 6, 6
G, 7, 7
H, 8, 8
I, 9, 9
J, 10, 10
K, 11, 11
;

data temp / view=temp;
    set person;
    if 3<x<8 and 3<y<8 then text=name;
    else do; sx=x; sy=y; end;
run;

proc sgplot data=temp;
    scatter x=sx y=sy;
    text x=x y=y text=text;
run;

Result:

 

 

Udklip.PNG

farshidowrang
Quartz | Level 8

Thank you very much!

Is it possible that I get the letters above the points?

 

Best regards

 

Farshid 

PeterClemmensen
Tourmaline | Level 20

Like this?

 

data person;
infile datalines delimiter=',';
input name $ X Y;
datalines;
A, 1, 1
B, 2, 2
C, 3, 3
D, 4, 4
E, 5, 5
F, 6, 6
G, 7, 7
H, 8, 8
I, 9, 9
J, 10, 10
K, 11, 11
;

data temp / view=temp;
    set person;
    if 3<x<8 and 3<y<8 then text=name;
run;

proc sgplot data=temp;
    scatter x=y y=y / datalabel=text datalabelpos=top;
run;
farshidowrang
Quartz | Level 8

Thank you very much! 

 

Best regards

 

Farshid 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 1289 views
  • 1 like
  • 2 in conversation