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

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

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisBrooks
Ammonite | Level 13

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;

View solution in original post

6 REPLIES 6
ChrisBrooks
Ammonite | Level 13

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;
sastuck
Pyrite | Level 9

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!

ChrisBrooks
Ammonite | Level 13

 Surely the PROC SGPLOT outputs a plot?

sastuck
Pyrite | Level 9

I'm not seeing anything besides the tables. Here's the log:

 

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
70
71 *series plot;
72 proc sort data=paper.Compustat_ExecuComp4 out=sorted;
73 by year;
74 run;
 
NOTE: There were 13346 observations read from the data set PAPER.COMPUSTAT_EXECUCOMP4.
NOTE: The data set WORK.SORTED has 13346 observations and 107 variables.
NOTE: PROCEDURE SORT used (Total process time):
real time 0.06 seconds
user cpu time 0.02 seconds
system cpu time 0.05 seconds
memory 30528.09k
OS Memory 62304.00k
Timestamp 03/31/2018 10:47:21 PM
Step Count 545 Switch Count 2
Page Faults 0
Page Reclaims 7331
Page Swaps 0
Voluntary Context Switches 16
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 54288
 
 
75
76 proc means data=sorted;
77 by year;
78 var salary;
79 output out=avg mean=avg_salary;
80 run;
 
NOTE: There were 13346 observations read from the data set WORK.SORTED.
NOTE: The data set WORK.AVG has 8 observations and 4 variables.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.09 seconds
user cpu time 0.09 seconds
system cpu time 0.01 seconds
memory 5003.82k
OS Memory 35820.00k
Timestamp 03/31/2018 10:47:21 PM
Step Count 546 Switch Count 13
Page Faults 0
Page Reclaims 541
Page Swaps 0
Voluntary Context Switches 39
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 264
 
 
81
82 proc sgplot data = sorted;
83 series x=year y=avg_salary;
ERROR: Variable AVG_SALARY not found.
84 title '';
85 run;
 
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SGPLOT used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 1700.28k
OS Memory 34532.00k
Timestamp 03/31/2018 10:47:21 PM
Step Count 547 Switch Count 1
Page Faults 0
Page Reclaims 281
Page Swaps 0
Voluntary Context Switches 6
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 0
 
86
87 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
99
 
User: apmorabito0
Messages: 79
 
 
 
 

FILLEDOUTLINEDMARKERS

 
 
 
 
ChrisBrooks
Ammonite | Level 13

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

sastuck
Pyrite | Level 9

awesome. thanks!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

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.

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
  • 6 replies
  • 1814 views
  • 2 likes
  • 2 in conversation