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

Hi I have this code for GPLOT but I want to change it into SGPLOT as I think there's more options to make it look nicer. Here's the code I have and I need help transforming it into sgplot:

 

proc sort data = dataname;
 by Month Hour;
run;

proc summary data = dataname;
 by Month Hour;
 var Load;
 output out = means (drop = _:) mean = mean n = n stderr = stderr;
run;

symbol1 i = j value = W font = marker c = vivb h = 1 line = 1 width = 1;
symbol2 i = j value = W font = marker c = bigb h = 1 line = 1 width = 1; 
symbol3 i = j value = W font = marker c = liolbr h = 1 line = 1 width = 1;
symbol4 i = j value = W font = marker c = lilg h = 1 line = 1 width = 1; 
symbol5 i = j value = W font = marker c = vilg h = 1 line = 1 width = 1;
symbol6 i = j value = W font = marker c = salmon h = 1 line = 1 width = 1; 
symbol7 i = j value = W font = marker c = vipk h = 1 line = 1 width = 1;
symbol8 i = j value = W font = marker c = lippk h = 1 line = 1 width = 1; 
symbol9 i = j value = W font = marker c = strbr h = 1 line = 1 width = 1;
symbol10 i = j value = W font = marker c = morbr h = 1 line = 1 width = 1; 
symbol11 i = j value = W font = marker c = debr h = 1 line = 1 width = 1;
symbol12 i = j value = W font = marker c = bib h = 1 line = 1 width = 1; 

proc gplot data = means;
axis1 order=(0 to 23 by 1);
 plot mean * Hour = Month / haxis=axis1;
 title 'Average Hourly Load for Every Month';
 format Month
run; 

Here's how it look with gplot:

 

Untitled.png

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

It's hard to say without knowing the structure of your data, but I think the following will get you started:

 

title 'Average Hourly Load for Every Month'; 
proc sgplot data = means;
 format Month; 
series y=mean x=Hour / group=Month; xaxis values=(0 to 23 by 1);
run;

View solution in original post

9 REPLIES 9
PaigeMiller
Diamond | Level 26

In this case, you want to use the SERIES command in PROC SGPLOT with the GROUP= option.

--
Paige Miller
matt23
Quartz | Level 8
How would the code look for sgplot then?
When I change it to sgplot, command 'plot' does not work anymore
PaigeMiller
Diamond | Level 26

@matt23 wrote:
How would the code look for sgplot then?
When I change it to sgplot, command 'plot' does not work anymore

As I said, you use the SERIES command. Here is the documentation if you are not familiar with it.

http://documentation.sas.com/?cdcId=pgmmvacdc&cdcVersion=9.4&docsetId=grstatproc&docsetTarget=n0yjdd...

--
Paige Miller
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Bookmark this page:

https://blogs.sas.com/content/graphicallyspeaking/

 

Its has code for pretty much any graphing activity you want to do, it is my one best source for anything sgplot/gtl related.

matt23
Quartz | Level 8
thank you, that is a great resource
Rick_SAS
SAS Super FREQ

It's hard to say without knowing the structure of your data, but I think the following will get you started:

 

title 'Average Hourly Load for Every Month'; 
proc sgplot data = means;
 format Month; 
series y=mean x=Hour / group=Month; xaxis values=(0 to 23 by 1);
run;
matt23
Quartz | Level 8
Yes, thank you, that is perfect.
Is there any way I can edit the look of each SERIES?
Rick_SAS
SAS Super FREQ

Yes. The easiest way (assuming you are using a modern version of SAS) is to use the STYLEATTRS statement.

 

 

proc sgplot data=have nocycleattrs;
styleattrs datacontrastcolors=(black bigb liolbr lilg vilg salmon vipk lippk strbr morbr debr bib);
series y=mean x=Hour / group=Month;
xaxis values=(0 to 23 by 1); run; 
run;

 

Reeza
Super User

I'm a fan of the data attribute maps. Having the data in a data set makes it a little more dynamic and easy to change/update IMO.

 

http://documentation.sas.com/?docsetId=grstatproc&docsetTarget=p18q268a3zxcl3n11lnnnq4cme8r.htm&docs...

 


@matt23 wrote:
Yes, thank you, that is perfect.
Is there any way I can edit the look of each SERIES?

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 9 replies
  • 2244 views
  • 2 likes
  • 5 in conversation