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
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;
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;
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;
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.
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!
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.
Ready to level-up your skills? Choose your own adventure.