Data visualization with SAS programming

SGPLOT for multiple variables

Reply
Occasional Contributor
Posts: 14

SGPLOT for multiple variables

Hi there!

I'm trying to draw some plot using proc sgplot;

for one variable, the code is as the following:

proc sgplot data= plot;
series y=A1 x=variable;
run;

 

However since there are options like colors following the series, and I actually want 10 series (y=a1, a2... a10) of y in the plot. Is there any easier way to draw these series of plots rather than writing 10 series?

 

Thanks!

Grand Advisor
Posts: 10,191

Re: SGPLOT for multiple variables

Often what your are thinking of requires restructuring your data so you can use a Group option.

The data should look like:

 

X  Y Group

1   1  A1

2   3  A1

1   5  A2

 

Proc transpose may work for that.

Then your sgplot code would look like

proc sgplot data= plot;
    series y=Y x=X / group=group;
run;

SAS Super FREQ
Posts: 1,075

Re: SGPLOT for multiple variables

If you have multiple columns, one for each response, you have two options:

  1. Use a series plot per column.  Using Cycleattrs, colors will be set differently for each series automatically.
  2. Transpose your data so you have a GROUP variable that has each series id.  Then have only one column for response.  Then you can use one SERIES statement with GROUP option.  This is the preferred way.

See http://blogs.sas.com/content/graphicallyspeaking/2015/06/28/attributes-priority-for-the-inquiring-mi...

SAS Super FREQ
Posts: 3,381

Re: SGPLOT for multiple variables

[ Edited ]

See this article on plotting multiple series. You might also want to be aware of some of the issues involved in Spaghetti Plots.

Ask a Question
Discussion stats
  • 3 replies
  • 327 views
  • 3 likes
  • 4 in conversation