Hi,
I am trying to create a graph using the SGPLOT procedure, and combine it with the GROUP option (call them group1 and group2). My problem is that group1 and group2 have very different values (group1 values are much higher than group2) and so I'm trying to figure out how to modify my code to keep group1 values on the left hand y-axis and group2 values on the right hand y-axis. My original code is below. Thanks a lot in advance for your help!
proc sgplot data=data_have ;
series x = date y= yvariable / group=treated ;
XAXIS LABEL = ' ' GRID VALUES = ('01jun2006'd TO '01sep2012'd BY 20) ;
YAXIS LABEL = 'Default Rate' /* GRID VALUES = (0 TO 10 BY 1)*/ ;
TITLE ' My title';
run;
quit;
To handle this situation, I would probably transpose the data such that the values for each group are in their own columns. Then, I would overlay two SERIES plots, assigning one series to the left axis and one series to the right axis (using the Y2AXIS option). That way, you can compare them independent of their ranges. The SGPLOT code would look something like this:
proc sgplot data=data_have ;
series x = date y= group1 ;
series x = date y= group2 / y2axis ;
XAXIS LABEL = ' ' GRID VALUES = ('01jun2006'd TO '01sep2012'd BY 20) ;
YAXIS LABEL = 'Default Rate' /* GRID VALUES = (0 TO 10 BY 1)*/ ;
TITLE ' My title';
run;
quit;
Hope this helps!
Dan
Well, hard to say from that snippet. What are your groups like? If you number the groups, say small one as 1, and large one as 2, then apply a format based on that number it will put 1 first an 2 next. Hard to tell if this is what your after though, provide test data (in the form of a datastep) and what the output should look like:
proc format;
value grp
1 = "Small group"
2 = "Big group";
run;
To handle this situation, I would probably transpose the data such that the values for each group are in their own columns. Then, I would overlay two SERIES plots, assigning one series to the left axis and one series to the right axis (using the Y2AXIS option). That way, you can compare them independent of their ranges. The SGPLOT code would look something like this:
proc sgplot data=data_have ;
series x = date y= group1 ;
series x = date y= group2 / y2axis ;
XAXIS LABEL = ' ' GRID VALUES = ('01jun2006'd TO '01sep2012'd BY 20) ;
YAXIS LABEL = 'Default Rate' /* GRID VALUES = (0 TO 10 BY 1)*/ ;
TITLE ' My title';
run;
quit;
Hope this helps!
Dan
I might also consider SGPANEL and Panel By your group variable. Use options to have the plots in one column to be one above the other and allow separate y axis values if needed.
If you try the SGPANEL suggestion from ballardw, be sure to use the UNISCALE=COLUMN option on the PANELBY statement. Otherwise, the scales on the row axis will be unified, and you'll get the same scaling problem. The nice thing about this approach is that it requires no data manipulation, and there's no chance of confustion about which series belongs to which axis. The code should look something like this:
proc sgpanel data=data_have ;
panelby treated / uniscale=column layout=rowlattice;
series x = date y= yvariable;
COLAXIS LABEL = ' ' GRID VALUES = ('01jun2006'd TO '01sep2012'd BY 20) ;
ROWAXIS LABEL = 'Default Rate' ;
TITLE ' My title';
run;
quit;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.