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

Dear all colleagues ;

I need you help , table below is my type of data, so i need to plot DAMDIM vs Estimate unsing SE as upper and lower limit, also as you see there are second variable BHB level for each DAMDIM observation (1 dAMDIM = 4 levels) please if you have any help that will be so kind for me , i tried to understand GPLOT but is so complicated with many options. 

 

THANK YOU SO Much  

 

Dam_DIM BHB_level Estimate Standard Error
40 0 2.3476 0.4174
40 1 2.171 0.2936
40 2 2.5354 0.854
40 3 1.11 1.7042
41 0 2.2681 0.3165
41 1 2.1614 0.2604
41 2 1.7039 0.9852
41 3 2.5988 1.2062
42 0 2.9415 0.3173
42 1 1.9979 0.2374
42 2 1.0917 0.7625
42 3 1.647 0.9816
43 0 1.8898 0.2728
43 1 2.4978 0.2094
43 2 1.1158 0.9858
43 3 2.7079 0.7616
44 0 2.5648 0.2558
44 1 2.0557 0.211
44 2 1.8988 0.6973
44 3 1.5242 0.5717
45 0 2.1302 0.2377
45 1 2.1301 0.176
45 2 2.3225 0.542
45 3 3.0647 0.8544
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

GPLOT is pretty old and has some esoteric behavior. SGPLOT is, generally easier to use and is where many new features have been added.

 

This is likely where I would start. First, note the data step. That is the preferred way to provide data on this forum so we do not have to guess as to variable names and properties may be. Most of places that allow you to set an error bar in the Sgplot code want an explicit upper and lower value for the plot. So the data step also allows us to add those.

The Sgplot is using a lot of default information such as the colors and markers of your current ODS Style. The X= and Y= are the axis that a variable is plotted against. Everything after the / are options. Group is how to specify a different plot for each level of another variable. The Scatter statement allow display of error-bars using the calculated variable.

I also show use of SGPANEL to create a separate graph for the levels of the BHB_level because your error bars overlap.

data have;
   input Dam_DIM 	BHB_level 	Estimate 	SE;
   SeUpper = estimate+SE;
   SeLower = estimate-SE;
datalines;
40 	0 	2.3476 	0.4174
40 	1 	2.171 	0.2936
40 	2 	2.5354 	0.854
40 	3 	1.11 	1.7042
41 	0 	2.2681 	0.3165
41 	1 	2.1614 	0.2604
41 	2 	1.7039 	0.9852
41 	3 	2.5988 	1.2062
42 	0 	2.9415 	0.3173
42 	1 	1.9979 	0.2374
42 	2 	1.0917 	0.7625
42 	3 	1.647 	0.9816
43 	0 	1.8898 	0.2728
43 	1 	2.4978 	0.2094
43 	2 	1.1158 	0.9858
43 	3 	2.7079 	0.7616
44 	0 	2.5648 	0.2558
44 	1 	2.0557 	0.211
44 	2 	1.8988 	0.6973
44 	3 	1.5242 	0.5717
45 	0 	2.1302 	0.2377
45 	1 	2.1301 	0.176
45 	2 	2.3225 	0.542
45 	3 	3.0647 	0.8544
;

proc sgplot data=have;
  /* if you want the points connected use this*/
  series x=Dam_DIM y=estimate / group=BHB_level
  ;
  scatter x=Dam_DIM y=estimate / group=BHB_level
                                yerrorlower=SeLower yerrorupper=SeUpper
  ;
run;

OR

proc sgpanel data=have;
  /* if you want the points connected use this*/
  panelby bhb_level/columns=1;
  series x=Dam_DIM y=estimate / 
  ;
  scatter x=Dam_DIM y=estimate / 
                                yerrorlower=SeLower yerrorupper=SeUpper
  ;
run;

View solution in original post

2 REPLIES 2
ballardw
Super User

GPLOT is pretty old and has some esoteric behavior. SGPLOT is, generally easier to use and is where many new features have been added.

 

This is likely where I would start. First, note the data step. That is the preferred way to provide data on this forum so we do not have to guess as to variable names and properties may be. Most of places that allow you to set an error bar in the Sgplot code want an explicit upper and lower value for the plot. So the data step also allows us to add those.

The Sgplot is using a lot of default information such as the colors and markers of your current ODS Style. The X= and Y= are the axis that a variable is plotted against. Everything after the / are options. Group is how to specify a different plot for each level of another variable. The Scatter statement allow display of error-bars using the calculated variable.

I also show use of SGPANEL to create a separate graph for the levels of the BHB_level because your error bars overlap.

data have;
   input Dam_DIM 	BHB_level 	Estimate 	SE;
   SeUpper = estimate+SE;
   SeLower = estimate-SE;
datalines;
40 	0 	2.3476 	0.4174
40 	1 	2.171 	0.2936
40 	2 	2.5354 	0.854
40 	3 	1.11 	1.7042
41 	0 	2.2681 	0.3165
41 	1 	2.1614 	0.2604
41 	2 	1.7039 	0.9852
41 	3 	2.5988 	1.2062
42 	0 	2.9415 	0.3173
42 	1 	1.9979 	0.2374
42 	2 	1.0917 	0.7625
42 	3 	1.647 	0.9816
43 	0 	1.8898 	0.2728
43 	1 	2.4978 	0.2094
43 	2 	1.1158 	0.9858
43 	3 	2.7079 	0.7616
44 	0 	2.5648 	0.2558
44 	1 	2.0557 	0.211
44 	2 	1.8988 	0.6973
44 	3 	1.5242 	0.5717
45 	0 	2.1302 	0.2377
45 	1 	2.1301 	0.176
45 	2 	2.3225 	0.542
45 	3 	3.0647 	0.8544
;

proc sgplot data=have;
  /* if you want the points connected use this*/
  series x=Dam_DIM y=estimate / group=BHB_level
  ;
  scatter x=Dam_DIM y=estimate / group=BHB_level
                                yerrorlower=SeLower yerrorupper=SeUpper
  ;
run;

OR

proc sgpanel data=have;
  /* if you want the points connected use this*/
  panelby bhb_level/columns=1;
  series x=Dam_DIM y=estimate / 
  ;
  scatter x=Dam_DIM y=estimate / 
                                yerrorlower=SeLower yerrorupper=SeUpper
  ;
run;
Ameurgen
Obsidian | Level 7

Thank you so much  Mr. ballardw

 yes, using sgplot seem to me a good presentation rather than gplot. 

thanks again.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 276 views
  • 0 likes
  • 2 in conversation