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.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
Phamhhm
Fluorite | Level 6
Thanks for your answer and advice.

Mr. Pham

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

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