BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Phamhhm
Fluorite | Level 6

Hi

 

I have a monthly time series from January 1960 to December 2017.

I know to plot the whole series with SGPLOT.

PROC SGPLOT DATA=XYZ;

series x=date  y=ABC;

xaxis values=('1jan60'd to '1dec17'd BY month);

RUN;

 

However, i would like to plot 4 sub-series on the same plot:

series1 only year 1960

series2 only year 1970

series3 only year 1980

series4 only year 1990

 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Welcome to the SAS forums. Note that I've moved your post to the graphics board as it's more related.

 

Regarding your question, I would suggest the following approach:

 

1. Use a WHERE clause to filter the data.

2. Create new variables month & year that will reflect the month and year

3. Same code with the WHERE filter and then use GROUP=YEAR and month as date instead. 

 

You'll probably need to customize this some more but hopefully it gets you started.

 

data temp;
set xyz;

month=month(date);
mon_name = put(date, monname3.);
year = year(date);

run;

proc sgplot data=temp;

where year in (1960, 1970, 1980, 1990);

series  x= month y=abc / group=year;

run;

View solution in original post

4 REPLIES 4
Reeza
Super User

Welcome to the SAS forums. Note that I've moved your post to the graphics board as it's more related.

 

Regarding your question, I would suggest the following approach:

 

1. Use a WHERE clause to filter the data.

2. Create new variables month & year that will reflect the month and year

3. Same code with the WHERE filter and then use GROUP=YEAR and month as date instead. 

 

You'll probably need to customize this some more but hopefully it gets you started.

 

data temp;
set xyz;

month=month(date);
mon_name = put(date, monname3.);
year = year(date);

run;

proc sgplot data=temp;

where year in (1960, 1970, 1980, 1990);

series  x= month y=abc / group=year;

run;
Phamhhm
Fluorite | Level 6

Thanks

Nice solution and very fast answer.

I just add two options: markers and xaxis values.

 

DATA temp;

SET OUT;

 

month=month(date);

mon_name = put(date,monname3.);

 

year = year(date);

RUN;

PROC SGPLOT DATA=temp;

WHERE year in (1960, 1970, 1980, 1990);

series x=month y=unemployment_A1 / markers group=year;

xaxis values=(1 TO 12);

RUN;

 

ChrisHemedinger
Community Manager

Grouped by year or grouped by decade?  Either way, you need a grouping variable, which you can derive from DATE in a DATA step.

 

If grouping by year, you can simply "clone" DATE and apply a YEAR. format.  But if it's by decade, you'll need to do a little calculation to create a value for each decade and store that in a new variable.

 

Then you can use the GROUP= option on your SERIES statement.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
Phamhhm
Fluorite | Level 6
Thanks for your answer and advice.

Mr. Pham

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 4 replies
  • 3743 views
  • 2 likes
  • 3 in conversation