Pekka
Pekka

Reputation: 2448

SAS - Plot multiple time series in one picture (long format data)

I have data like this:

data mydata;
    input date class y;
    datalines;
    19900 1 10
    19900 2 11
    19900 3 14
    20000 1 12
    20000 2 15
    20000 3 17
;
run;

Now I want to plot date - y time series. I want to get one line for each class.

This code achieves already just what I am trying to do:

proc transpose data=mydata out=transposed;
    id class;
    by date;
run;

proc sgplot data=transposed;
    series x=date y=_1;
    series x=date y=_2;
    series x=date y=_3;
    yaxis label="y";
run;

But this doesn't work for me because the number of class variables might be changing. I suppose I could use some kind of macro loop there but then the code starts to get pretty complicated.

I would like to know if there is some feature or statement which produces the plot easily. Preferably even without proc transpose statement.

I am using SAS 9.3 but soon moving to 9.4 so 9.4 specific answers are welcome as well.

Thanks.

Upvotes: 0

Views: 2207

Answers (1)

Pekka
Pekka

Reputation: 2448

Ok I am an idiot. Here is the answer:

proc sqplot data=mydata;
    series x=date y=class / group=class;
run;

Upvotes: 1

Related Questions