fly36
fly36

Reputation: 83

How to do sub plot using sas

I want to make a simple time series line plot without highlighting any dots on the line. I can plot var1 and var2 using the following code.

   title "Title";
   proc gplot data=test;

      plot var1 *var2 /overlay grid  hminor=0 ;
   run;
   quit;

However I want to add another variable into the plot. I tried the following code. Because the scale of var1 and var3 are quite large, so var3 are not properly scaled in the graph. Can anyone teach me how to use different scale for var1 and var3 please.

   title "Title";
   proc gplot data=Test;

      plot var1 *var2   Var3*var2 /overlay grid  hminor=0 ;
   run;
   quit;

Additionally, may I ask whether sas can do subplot as matlab please. Essentially, I got one big graph with two separate sub-graph. If possible, please teach me how to achieve this. I tried vpercent = 50, but it seems there are something wrong in my code.

   proc gplot data=Test  vpercent=50;

      plot VAR1 *VAR2   VAR3*VAR2 /overlay grid  hminor=0 ;

   run;
   quit;

With Thanks

Upvotes: 0

Views: 981

Answers (2)

SunnyRJ
SunnyRJ

Reputation: 393

Here is some SAS code that builds on Reeza's excellent example and suggestion to use SGPANEL. See the PANELBY statement and the options used there.

*** SUBSET DATA AND SORT ***;
proc sort data=sashelp.stocks  out=ibm;
    where stock='IBM';
    by date;
run;

*** TRANSPOSE DATA FROM "SHORT-AND-WIDE" TO "LONG-AND-THIN" ***;
proc transpose data=ibm  out=ibm_t;
    by date;
    var open volume;
run;


proc sgpanel data=ibm_t;

    *** ROW LATTICE OPTION STACKS PLOTS ***;
    *** UNISCALE OPTION LETS EACH PANEL HAVE IT'S OWN SCALE ***;
    *** NOVARNAME SUPPRESSES LABEL FOR THE Y-AXIS ON THE RIGHT SIDE ***;
    panelby _name_ / layout=rowlattice uniscale=column novarname;

    series x=date y=col1;

    *** SUPPRESS LABEL FOR THE Y-AXIS ON THE LEFT SIDE ***;
    rowaxis display=(nolabel);
run;

Upvotes: 1

Reeza
Reeza

Reputation: 21274

Assuming I understand what you mean, if you have access to SGPLOT you can specify that X3 should be on a different axis. Here's an example with the SASHELP.STOCKS data which plots the open price on one Y axis and then the trade volume on the second Y axis.

proc sgplot data=sashelp.stocks;
where stock='IBM';
series x=date y=open;
series x=date y=volume/y2axis;
run;quit;

Upvotes: 2

Related Questions