Hello,
I want to show a series plot which traces average CEO salary over the years 2010-2017. I've never done a plot of this type, however, and am looking for some help. I imagine I am correct in choosing year for my x axis, but my question pertains to the y axis. The variable salary, which is each CEO's salary, obviously won't cut it because there are thousands of observations per year for this variable. Am I correct in thinking that I need an average annual salary per CEO per year for this series plot to work? What would that datastep look like? I would like to output a new dataset so that I don't mess up the one I currently have. Any help is appreciated!
* Series plot; PROC SGPLOT DATA = paper.Compustat_ExecuComp4; SERIES X = year Y = salary; TITLE ''; RUN;
-SAStuck
I would think you want an average of all the CEO salaries for each particular year. You need to first sort your data and then use Proc Means to get your averages - you haven't supplied sample data so here is some untested code to get you started.
proc sort data=paper.Compustat_ExecuComp4 out=sorted;
by year;
run;
proc means data=sorted;
by year;
var salary;
output out=avg mean=avg_salary;
run;
proc sgplot data = avg;
series x=year y=avg_salary;
title '';
run;
I would think you want an average of all the CEO salaries for each particular year. You need to first sort your data and then use Proc Means to get your averages - you haven't supplied sample data so here is some untested code to get you started.
proc sort data=paper.Compustat_ExecuComp4 out=sorted;
by year;
run;
proc means data=sorted;
by year;
var salary;
output out=avg mean=avg_salary;
run;
proc sgplot data = avg;
series x=year y=avg_salary;
title '';
run;
I implemented you code:
*series plot; proc sort data=paper.Compustat_ExecuComp4 out=sorted; by year; run; proc means data=sorted; by year; var salary; output out=avg mean=avg_salary; run; proc sgplot data = sorted; series x=year y=avg_salary; title ''; run;
just changing "age" to "sorted" as you'll see above. This code output a table of summary statistics for each year, but I was hoping for a series plot? What do I need to add?
Thanks for the help!
Surely the PROC SGPLOT outputs a plot?
I'm not seeing anything besides the tables. Here's the log:
FILLEDOUTLINEDMARKERS
There's an error in the log - the proc Means outputs a data set called avg so replace data=sorted with data=avg in your Proc Sgplot code
awesome. thanks!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.