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

There are cleaner ways, but I have to run to a meeting, and this is the way I remember off of the top of my head.  Your SAS/GRAPH statements have no effect on ODS Graphics.

data new;
 input Year li ui;
 v = 'v';
 c = '^';
 datalines;
2015       1200       1360
2014       1170       1330
2013       1170       1330
2012       1140       1330
2011       1130       1320
2010       1110       1310
2009       1140       1310
2008       1120       1290
2007       1130       1300
2006       1150       1310
;

ods html body='b.html';
proc sgplot data =new noautolegend;
  scatter x=year y=li / markerchar=v;
  scatter x=year y=ui / markerchar=c;
run;
ods html close;
sas_user4
Obsidian | Level 7
​Thanks a lot Warren. This is excellent but how can I add the confidence
limits (clm cli)? Are these options are only available using "reg"?
Rick_SAS
SAS Super FREQ

I think you might enjoy reading a basic introduction to the SG (=statistical graphics) procedures. It will give you an understanding of how different statements work. 

 

sas_user4
Obsidian | Level 7
Thanks a lot, Rick!
sas_user4
Obsidian | Level 7

Warren,

I figured out the issue, my mistake and THANKS for your help.

 

WarrenKuhfeld
Rhodochrosite | Level 12
proc sgplot data=new noautolegend nocycleattrs;
  symbolchar char='2038'x name=c;
  symbolchar char='0087'x name=v;
  reg x=year y=li / cli clm nomarkers;
  reg x=year y=ui / cli clm nomarkers;
  scatter x=year y=li / markerchar=v;
  scatter x=year y=ui / markerchar=c;
run;
sas_user4
Obsidian | Level 7
Thanks Warren but the code did not work! I appreciate your help.
WarrenKuhfeld
Rhodochrosite | Level 12

It makes regression lines, confidence limits, prediction limits, and the special symbols that you want.  Either you are using a really old SAS release that does not support the statements I provided, or I don't know what you want.  Either way, I tested my code, and it does work.  Rick gave you some references.  I also suggest searches for the "SAS Graphically Speaking" blog and my basic book "Basic ODS Graphics Examples".  Cheers.

sas_user4
Obsidian | Level 7
Thanks Warren. I use SAS 9.4 and it does support all these commands. I went
through the refs but not much I could get for this specific problem. I
re-run the code again very carefully and I received the error messages:

ERROR: Variable V not found.
ERROR: Variable C not found.

This is the full code I am using:

data new;
input year lq uq;
datalines;
2015 1200 1360
2014 1170 1330
2013 1170 1330
2012 1140 1330
2011 1130 1320
2010 1110 1310
2009 1140 1310
2008 1120 1290
2007 1130 1300
2006 1150 1310
;
proc sgplot data=new noautolegend nocycleattrs;
symbolchar char='2038'x name=c;
symbolchar char='0087'x name=v;
reg x=year y=lq / cli clm nomarkers;
reg x=year y=uq / cli clm nomarkers;
scatter x=year y=lq / markerchar=v;
scatter x=year y=uq / markerchar=c;
run;
WarrenKuhfeld
Rhodochrosite | Level 12

Ask yourself why you got that message.  Look at the data set.  Are those variables there?  Then what can you do?  Was there a different version that has them there?  I could tell you precisely what to do but if you are going to become a productive SAS user, you need to learn to carefully look at what is going on in your code.

sas_user4
Obsidian | Level 7

I believe the variables c and v need to be added to the dataset but I am not sure about the right way of adding them.

I use this other code:

 

symbolchar char='2038'x;
symbolchar char='0087'x;

proc gplot data=new;
plot lq*year ;
plot2 uq*year ;
run;
quit;

 

I think I need y on x-axis and the two variables lq and uq on the y-axis.

Jay54
Meteorite | Level 14

I am not sure of intention with this code, but, the SCATTER statement should likely have MARKERATTRS=(SYMBOL=c).

sas_user4
Obsidian | Level 7

Hi Sanjay,

The original question is I am trying to prepare a scatterplot with the lower quartile (lq) on the vertical axis versus the year on the horizontal axis and to mark these observations on the plot with the character v.  Also on the same plot, I need to show the upper quartile (uq) plotted against the year and to mark these points with a ^. I am interested in showing confidence intervals or prediction intervals on a plot.

 

I used this code as you recommended:

 

data new;
input year lq uq;
datalines;
2015 1200 1360
2014 1170 1330
2013 1170 1330
2012 1140 1330
2011 1130 1320
2010 1110 1310
2009 1140 1310
2008 1120 1290
2007 1130 1300
2006 1150 1310
;
proc sgplot data=new noautolegend nocycleattrs;
symbolchar char='2038'x name=c;
symbolchar char='0087'x name=v;
reg x=year y=lq / cli clm nomarkers;
reg x=year y=uq / cli clm nomarkers;
scatter x=year y=lq / MARKERATTRS=(SYMBOL=c);
scatter x=year y=uq / MARKERATTRS=(SYMBOL=v);
run;

 

It runs but I still did not get the symbol charater ^ or v for either variable. And the uq does not appear on the y-axis?

Jay54
Meteorite | Level 14

This works with my SAS 9.40M3 version.  Should work with any SAS 9.4.  I used Microsoft's Character map app to find the encoding for the characters you want.  I also increased the marker size as the characters occupy only a small part of the character space.   Note, with characters, the center of the character bounding box will go at the (x, y) location.  So, if your character is offset, "v" is likely offset down, and "^" is likely offset up, you will get them off the (x, y) value a bit.  You can use the options on the SYMBOLCHAR statement (hoffset, voffset, rotate, scale) to position them correctly.  You can increase the SIZE option to see them more clearly.

 

SymbolChar.png

 

 

 

 

proc sgplot data=new noautolegend nocycleattrs;
symbolchar char='005e'x name=c;
symbolchar char='0076'x name=v;
reg x=year y=lq / cli clm nomarkers;
reg x=year y=uq / cli clm nomarkers;
scatter x=year y=lq / MARKERATTRS=(SYMBOL=c size=30);
scatter x=year y=uq / MARKERATTRS=(SYMBOL=v size=25);
run;

Jay54
Meteorite | Level 14

You really only need:

 

proc sgplot data=new noautolegend nocycleattrs;
symbolchar char='005e'x name=c;
symbolchar char='0076'x name=v;
reg x=year y=lq / cli clm MARKERATTRS=(SYMBOL=c size=30);
reg x=year y=uq / cli clm MARKERATTRS=(SYMBOL=v size=25);

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 32 replies
  • 3807 views
  • 7 likes
  • 5 in conversation