Merging class panels with SGPANEL for SAS

453 Views Asked by At

Suppose I have a data set with class variable with 4 levels: A, B, C and D. If I want to creater four series plots in SAS Studio I can run the following code using proc sgpanel.

proc sgpanel data = name;
panelby class;
series X = var1 Y = var2 / group = some_factor;
run;

How can modify this code to instead create 2 panels where the first panel has the graphs of both A and B and the second C and D? A naive solution would be to add a "dummy" 0-1 variable to the data set and using panelby dummy. However I was hoping for a more elegant solution!

Edit: To clarify I want to have different graphs for A and B in the same panel, not combine data into one graph.

Graphs from the question

1

There are 1 best solutions below

2
On

If you're aiming to combine the A/B and C/D into one series each, then this is straightforward.

Using this sashelp.class example as the base:

proc sgpanel data=sashelp.class;
panelby age;
series x=height y=weight;
run;

We create a format that combines the class values in whatever fashion is preferred:

proc format;
  value agegroupf
  11-13="Younger"
  14-16="Older"
  ;
quit;

Then apply the format.

proc sgpanel data=sashelp.class;
format age agegroupf.;
panelby age;
series x=height y=weight;
run;

This won't show separate plots for the individual class values on the panel; if that's desired, then group could be used with a second class variable (an identical, but second, variable). However, if group is already being used, as in the updated question, it might be complicated to implement this. Separate series statements could be used to show each, but this is perhaps additionally complex.

Here's one way to do the overlaid groups - just copying age to age2.

data class;
  set sashelp.class;
  age2 = age;
run;

proc sgpanel data=class;
format age agegroupf.;
panelby age;
series x=height y=weight/group=age2;
run;

I think that in GTL you might be able to do it without actually creating a second variable, but I don't think it's possible in regular SGPanel.