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.

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
Phamhhm
Fluorite | Level 6
Thanks for your answer and advice.

Mr. Pham

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 4215 views
  • 2 likes
  • 3 in conversation