BookmarkSubscribeRSS Feed
Forecaster
Obsidian | Level 7

I'm trying to plot multiple time series plot which looks like a spahetti plot. I'm trying to avoid spaghetti plot by using lattice or panel like plots.

 

Here is the SAS dataset to replicate,I have dataset called "temp" with grouping variable called group. The data is time series with time variable "date" and y variable "air".

 

data alldata1;
		set sashelp.air;

		group = "REF";

		keep date air group;
run;

data alldata2;
		set sashelp.air;

		group = "A1";

		air=air+30;

		keep date air group;
run;

data alldata3;
		set sashelp.air;

		group = "A2";

		air=air+60;

		keep date air group;
run;

data alldata4;
		set sashelp.air;

		group = "A3";

		air=air-30;

		keep date air group;
run;

data alldata5;
		set sashelp.air;

		group = "A4";

		air=air-60;

		keep date air group;
run;

data temp;
		    set alldata1
			alldata2
			alldata3
			alldata4
			alldata5;

run;

The grouping variable "group" has 5 categories. "REF", A1,A2,A3,A4. I need to creat a chart like the one below where "REF" group highlighted in "red" and each category is highlighted in blue and the rest of the category in light grey.

 

spagetti.JPG

 

Below are my questions:

  1. How do I replicate thie above using a SAS procedure ?
  2. how can I choose the number of rows and columns, in the above chart it is 2 (rows) by 2 (colums). What if I have more than 8 categories and want to display it as ?
  3. how can I export this cart as ps or png high resolution file?

 

Thanks

3 REPLIES 3
Reeza
Super User

Some answers to help you get started. 

1. SGPLOT Series graph, use a BY statement for different graphs or SGPANEL, given sample SGPLOT looks easier.

2. Either PROC GREPLAY and ODS DOCUMENT to control the layout or output to a PDF file with columns=2. It doesn't matter how many categories exist if you use  a BY statement it will automatically create them all. 

3. Specify the device type under ODS GRAPHICS options statements. 

 

What SAS version do you have? The graphics options vary a bit in the last few. For example, AttributeMaps will allow you to control the colours the easiest and is in the later releases. 

 

 

Forecaster
Obsidian | Level 7
I have SAS 9.4. Can you please show me how to use SAS sgplot? I have provided a reproducible example. I tried sgpanel but not sure how to use all series at once? Thanks
rogerjdeangelis
Barite | Level 11
HAVE
====

Up to 40 obs from temp total obs=576

Obs    DATE     AIR    GROUP    AIR1

  1    JAN49    142     A1       112
  2    JAN49    172     A2       142
  3    JAN49    202     A3       172
  4    JAN49    232     A4       202
  5    FEB49    148     A1       118
  6    FEB49    178     A2       148
  7    FEB49    208     A3       178
  8    FEB49    238     A4       208
....
569    NOV60    420     A1       390
570    NOV60    450     A2       420
571    NOV60    480     A3       450
572    NOV60    510     A4       480
573    DEC60    462     A1       432
574    DEC60    492     A2       462
575    DEC60    522     A3       492
576    DEC60    552     A4       522

WANT ( see below)


FULL SOLUTION
=============

data have;
  set sashelp.air;
  do group="A1","A2","A3","A4";
       air1=air;
       air=air+30;
       output;
  end;
run;quit;

options orientation=landscape;
ods pdf file="d:/pdf/panel.pdf"  notoc;
title "Group Panels";
proc sgpanel data=temp;
panelby group / columns = 2 rows = 2;
series x=date y=air;
series x=date y=air1 ;
run;quit;

SGPanel19.png

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 3431 views
  • 0 likes
  • 3 in conversation