BookmarkSubscribeRSS Feed
danielhu
Calcite | Level 5

Hi, I will need to calculate the (absolute) mean change in scores between years for the following example. There are some firm that may only have scores for certain years. This is really tricky, hope i can render some help here.

YearFirmScores
2005A5
2005B8
2006A7
2006C4
2007A8
2007B10
2007D8
2007E3
2 REPLIES 2
Reeza
Super User

What is your expected output?

Steelers_In_DC
Barite | Level 11

I have the time right now so I'm taking a guess at what you are looking for.  An example of what you are looking for would be helpful. Try this:

data have;

infile cards;

input Year Firm $ Scores;

cards;

2005 A 5

2005 B 8

2006 A 7

2006 C 4

2007 A 8

2007 B 10

2007 D 8

2007 E 3

;

run;

proc sql;

create table prep as

select distinct year, sum(scores) as sum_scores

from have

group by year

order by year;

data start(drop=l_sum_scores);

set prep;

by year;

l_sum_scores = lag(sum_scores);

diff_scores = abs(l_sum_scores - sum_scores);

run;

proc sql;

create table want as

select *,mean(diff_scores) as mean_scores

from start;

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!

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.

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
  • 2 replies
  • 2740 views
  • 0 likes
  • 3 in conversation