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?

 

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