Hey all!
I have a table that looks like this:
ID TERM CUR GPA
ABC 1 3.5
ABC 2 3.67
ABC 3 3.43
XYZ 1 2.67
XYZ 2 2.69
XYZ 3 3.01
I want to calculate the Percent change for each group of Student ID and then the trend for each term.
I have been trying to calculate the percent change for each student ID as:
a = lag(CUR_GPA)
change = ((current-a)/a)
mean = mean(change)
If I follow this the 'a' value for each first student ID will be 0 because I wish to group by each ID and do these calculations on particular groups.
Thank you
Do you want a trend, or do your want record-by-record changes? You code suggests the latter while you title suggest the former?
Please provide a example of how you want the results to look like.
Hey! Thanks for replying.
I want to calculate the trend based on the record by record change i.e. a mean of the change.
Thanks
And I repeat, how do your want you output to look? Do you want a report, without saving a new dataset file? Do you want a dataset with one observation per id, containing a new average percent change? Something else?
I am trying to create a new data set with one observation per id.
Thanks
You apparently want the average relative change within a group, not a trend as defined by a regression line slope. If so:
data have;
input ID $3. TERM CUR_GPA;
datalines;
ABC 1 3.5
ABC 2 3.67
ABC 3 3.43
XYZ 1 2.67
XYZ 2 2.69
XYZ 3 3.01
run;
data want (keep=id mean_dif);
set have;
by id;
difsum+dif(cur_gpa);
nid+1;
if first.id then do;
difsum=0;
nid=1;
end;
if last.id;
mean_dif=difsum/(nid-1);
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.