BookmarkSubscribeRSS Feed
mounikag
Obsidian | Level 7

Hi Team,

 

I am trying to generate a figure by using proc sgplot  and I want the markers symbols to be present outside the figure below the X-axis at wek 0 , week 4 and week 24 etc and  here is the code  I am using  and output . But I am getting the markers(trianglefilled homedown filled) inside the figure :  Could you pleas let me know how to work to get the markers outside and here is the sample figure iam attaching and also the pictures of my figure of what iam getting and what i need 

 


proc sgplot data=tmp2 ;
xaxis integer label ='Week' values=(0 to 52 by 4 ) /*offsetmin=0.05 offsetmax=0.05*/ ;
yaxis integer label ='Seroprotection Rate (%) with 95% confidence intervals' /*offsetmin=0.08*/ values=(0 to 100 by 10) ;

scatter x=byn2 y=line1 / /*datalabel = col1 datalabelattrs=(color=blue size=5.5 style=italic weight=bold)*/
yerrorlower=lcl1 yerrorupper=ucl1
legendlabel = 'X'
markerattrs=(symbol=circlefilled size=6 color=Blue)
errorbarattrs= (color=Blue)
;
series x=byn2 y=line1/
legendlabel = 'X'
lineattrs = (pattern=shortdash thickness=2 color=Blue)
;
scatter x=byn2 y=line2 / /*datalabel = col2 datalabelattrs=(color=orange size=5.5 style=italic weight=bold)*/
yerrorlower=lcl2 yerrorupper=ucl2
legendlabel = 'Y'
markerattrs=(symbol=starfilled size=6 color=Orange)
errorbarattrs= (color=orange)
;
series x=byn2 y=line2/
legendlabel = 'Y'
lineattrs = (pattern=shortdash thickness=2 color=Orange)
;
scatter x=byn2 y=line3 / /*datalabel = col1 datalabelattrs=(color=Blue size=5.5 style=italic weight=bold)*/
yerrorlower=lcl1 yerrorupper=ucl1
legendlabel = 'Z'
markerattrs=(symbol=circlefilled size=6 color=Blue)
errorbarattrs= (color=Blue)
;
series x=byn2 y=line3/
legendlabel = 'Z'
lineattrs = (pattern=solid thickness=2 color=Blue)
;
scatter x=byn2 y=line4 / /*datalabel = col2 datalabelattrs=(color=Orange size=5.5 style=italic weight=bold)*/
yerrorlower=lcl2 yerrorupper=ucl2
legendlabel = 'a'
markerattrs=(symbol=starfilled size=6 color=Orange)
errorbarattrs= (color=orange)
;
series x=byn2 y=line4/
legendlabel = 'a'
lineattrs = (pattern=solid thickness=2 color=Orange)
;
scatter x=byn2 y=line5 /
legendlabel = 'b'
markerattrs=(symbol=trianglefilled size=8 color=Blue)
;
scatter x=byn2 y=line6 /
legendlabel = 'c'
markerattrs=(symbol=HomeDownFilled size=8 color=Orange)
;

xaxistable byn2 /x=line5 location=outside label='b'
valueattrs=(color=blue)
labelattrs=(color=blue)
titleattrs=(color=blue);

keylegend / location=outside position=bottom across=2 down=4 valueattrs=(size=9) ;
run ;

 

 

 

7 REPLIES 7
Ksharp
Super User
/*
NOTICE:
using UNICODE SAS to run the following code.
*/

data have;
 set sashelp.stocks;
 if year(date) in (2004:2006);
 if stock='IBM' and month(date) in (1 4 6 10) then flag='▲';
 if stock='Intel' and month(date) in (2 8) then flag='▲';
 if stock='Microsoft' and month(date) in (5 9) then flag='▲';

 if stock='IBM' then do;group=1;class='AAAAA';end;
  else do;group=2;class='BBBBB';end;
run;

ods graphics /attrpriority=none;
proc sgplot data=have;
series x=date y=close/group=stock markers 
grouplc=group groupmc=group lineattrs=(pattern=solid);
xaxistable flag/class=class x=date colorgroup=group;
keylegend /location=inside position=e across=1;
run;
tdahiya
Calcite | Level 5

How do you get SAS unicode for markers to work? I am unable to get 'trianglefilled' using "(*ESC*){unicode '25b2'x}" on SAS9.4

 

data have;
set sashelp.stocks;
if year(date) in (2004:2006);
if stock='IBM' and month(date) in (1 4 6 10) then flag="(*ESC*){unicode '25b2'x}";
if stock='Intel' and month(date) in (2 8) then flag="(*ESC*){unicode '25b2'x}";
if stock='Microsoft' and month(date) in (5 9) then flag="(*ESC*){unicode '25b2'x}";

if stock='IBM' then do;group=1;class='AAAAA';end;
else do;group=2;class='BBBBB';end;
run;

*ods graphics /attrpriority=none;
proc sgplot data=have;
series x=date y=close/group=stock markers
grouplc=group groupmc=group lineattrs=(pattern=solid);
xaxistable flag/class=class x=date colorgroup=group;
keylegend /location=inside position=e across=1;
run;

output.png

 

 

Ksharp
Super User

Try UNICODE() function , make sure your sas session 's encoding is utf8 or others which support triangle characters.

 

data have;
set sashelp.stocks;
if year(date) in (2004:2006);
if stock='IBM' and month(date) in (1 4 6 10) then flag=unicode('\u25b2');
if stock='Intel' and month(date) in (2 8) then flag=unicode('\u25b2');
if stock='Microsoft' and month(date) in (5 9) then flag=unicode('\u25b2');

if stock='IBM' then do;group=1;class='AAAAA';end;
else do;group=2;class='BBBBB';end;
run;

*ods graphics /attrpriority=none;
proc sgplot data=have;
series x=date y=close/group=stock markers
grouplc=group groupmc=group lineattrs=(pattern=solid);
xaxistable flag/class=class x=date colorgroup=group;
keylegend /location=inside position=e across=1;
run;

Ksharp_0-1675157707934.png

 

DanH_sas
SAS Super FREQ

@Ksharp 's technique is the best way to get special Unicode characters in your actual data. We do not evaluate ODS escapements in the data itself -- only in strings provided through the syntax.

 

To solve this request, the symbol needed to be in the data; but you should not have to use this technique for situations where the symbols are plotted by a statement that supports marker symbols (SCATTER, SERIES, etc), as these font symbols can be accessed via the SYMBOLCHAR statement.

jabujakan
Calcite | Level 5

Hi everyone! I have 4 variables that are 0/1 responses. For example: Input GroupA GroupB GroupC GroupD; datalines ; 1 0 0 1 1 0 1 0 0 0 0 1 0 1 1 1 etc etc. How would I plot each of the variables into ONE vbar graph? Currently what I have: PROC SGPLOT; VBAR GroupA GroupB GroupC GroupD; and it does not work for me. Thank you!

Ksharp
Super User
/*
All your variables "GroupA GroupB GroupC GroupD" are category variable.
But VBAR is usually for continuous variable.
So what graph you want to output ,could you post an example ?
Or maybe you want this ?
*/

data have;
 Input GroupA GroupB GroupC GroupD; 
datalines ; 
1 0 0 1 
1 0 1 0 
0 0 0 1 
0 1 1 1
0 1 1 1 
1 1 1 1 
1 1 1 1 
;
data have;
 set have;
 id+1;
run;
proc transpose data=have out=want;
by id;
run;
proc sgplot data=want pctlevel=group;
vbar _NAME_/group=col1 stat=percent;
run;

Ksharp_0-1681386166962.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!

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